static VALUE ServiceModule_service_name(VALUE self, VALUE name) { struct Service *ruby_service; struct Client *ruby_client; Check_Type(name, T_STRING); rb_iv_set(self, "@ServiceName", name); ruby_service = make_service(StringValueCStr(name)); set_service(self, ruby_service); if(ircncmp(ruby_service->name, StringValueCStr(name), NICKLEN) != 0) rb_iv_set(self, "@ServiceName", rb_str_new2(ruby_service->name)); clear_serv_tree_parse(&ruby_service->msg_tree); dlinkAdd(ruby_service, &ruby_service->node, &services_list); hash_add_service(ruby_service); ruby_client = introduce_client(ruby_service->name, ruby_service->name, TRUE); rb_iv_set(self, "@client", client_to_value(ruby_client)); rb_iv_set(self, "@langpath", rb_str_new2(LANGPATH)); return name; }
/* Determine whether an ERROR message is safe to show (no IP address in it) */ static int is_safe_error(const char *message) { char prefix2[100]; const char *p; if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25)) return 1; snprintf(prefix2, sizeof prefix2, "Closing Link: 127.0.0.1 %s (", me.name); if (!strncmp(message, prefix2, strlen(prefix2))) return 1; if (!strncmp(message, "Restart by ", 11)) return 1; if (!strncmp(message, "Terminated by ", 14)) return 1; if (!ircncmp(message, "Closing Link", 12)) return 0; if (strchr(message, '[')) return 0; p = strchr(message, '.'); if (p != NULL && p[1] != '\0') return 0; if (strchr(message, ':')) return 0; return 1; }
/* * this will replace all occurances of "word" in "buf" with "subst" * -demond */ static void replace(char *buf, char *word, char *subst, int size) { char *p = buf; int len1 = strlen(word), len2 = strlen(subst); while (*p) if (!ircncmp(p, word, len1)) { if (p + len2 + strlen(p + len1) > buf + size) return; memmove(p + len2, p + len1, strlen(p + len1) + 1); memmove(p, subst, len2); p += len2; } else p++; }
/* Now, our job is a bit harder. I will scan through the SPOOF_FILE * and read all auths{} (assuming they are written in our line formatting..), * then rewrite them skipping the one to delete. --adx */ static void mo_delspoof(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { #ifdef SPOOF_FILE FBFILE *f, *fout; int ignore_it = 1, spoof_found = 0; char buffer[1024], *tmp; #endif const char *user = NULL; char *host = NULL; if (MyConnect(source_p) && !IsOperAdmin(source_p)) { sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, parv[0], "DELSPOOF"); return; } if (parv[1] == NULL || !*parv[1]) { if (MyConnect(source_p)) sendto_one(source_p, ":%s NOTICE %s :Syntax: /DELSPOOF <user@host>", me.name, source_p->name); return; } /* check user@host mask */ (void) collapse(parv[1]); host = strchr(parv[1], '@'); if (host != NULL) { user = parv[1]; *host = '\0'; host++; } else { user = "******"; host = parv[1]; } #ifdef PROPAGATE_SPOOF sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT, ":%s DELSPOOF %s@%s", source_p->name, user, host); #endif #ifdef SPOOF_FILE if ((f = fbopen(SPOOF_FILE, "r")) == NULL) { sendto_realops_flags(UMODE_ALL, L_ALL, "Could not open %s file, auth for %s@%s not deleted " "(requested by %s)", SPOOF_FILE, user, host, source_p->name); return; } if ((fout = fbopen(SPOOF_FILE ".new", "w")) == NULL) { sendto_realops_flags(UMODE_ALL, L_ALL, "Could not create %s.new file, auth for %s@%s not " "deleted (requested by %s)", SPOOF_FILE, user, host, source_p->name); return; } while (fbgets(buffer, 1024, f)) { if (!ircncmp(buffer, "auth {", 6)) { /* don't process it yet.. we have to check whether the user="******"; field * matches the user@host mask which is being deleted */ ignore_it = 1; continue; } /* a simple parser substitute... */ for (tmp = buffer; *tmp == '\t' || *tmp == ' '; tmp++) ; if (!ircncmp(tmp, "user", 4)) { for (tmp += 4; *tmp == '\t' || *tmp == ' '; tmp++) ; if (*tmp == '=') { for (++tmp; *tmp == '\t' || *tmp == ' '; tmp++) ; if (*tmp == '\"') { /* yuppi, we've just reached the user="******"; field */ int matches; char *tmp2 = strchr(++tmp, '\"'); if (tmp2 != NULL) *tmp2 = '\0'; tmp2 = strchr(tmp, '@'); /* is it matching our mask? */ if (tmp2 == NULL) matches = !irccmp(user, "*") && !irccmp(host, tmp); else { *tmp2++ = '\0'; matches = !irccmp(user, tmp) && !irccmp(host, tmp2); } if (!matches) { /* no.. so leave it unchanged */ if (ignore_it) { ignore_it = 0; fbputs("auth {\n", fout, 7); /* user="******" should be the first field in the auth {}; block, * otherwise we could have problems... */ } fbputs("\tuser = \"", fout, 9); if (tmp2 == NULL) fbputs("*", fout, 1); else fbputs(tmp, fout, strlen(tmp)); fbputs("@", fout, 1); fbputs(tmp2, fout, strlen(tmp2)); fbputs("\";\n", fout, 3); } else { /* we've got it! - omit and continue working */ spoof_found = 1; } continue; } } } if (!ignore_it) fbputs(buffer, fout, strlen(buffer)); } fbclose(f); fbclose(fout); if (!spoof_found) { if (MyConnect(source_p)) sendto_one(source_p, ":%s NOTICE %s :No auth for %s@%s found", me.name, source_p->name, user, host); unlink(SPOOF_FILE ".new"); return; } unlink(SPOOF_FILE); rename(SPOOF_FILE ".new", SPOOF_FILE); rehash(0); #endif #ifdef LOG_SPOOF sendto_realops_flags(UMODE_ALL, L_ALL, "%s deleted auth for %s@%s", source_p->name, user, host); #endif }
static void ss_server(struct Luser *lptr, int ac, char **av) { struct Server *servptr, *hub; char argbuf[MAXLINE + 1], str[MAXLINE + 1]; char *target; /* target server */ int maxusers, /* -maxusers */ minusers, /* -minusers */ info; /* -info */ int ii, alen, cnt; if (ac < 2) { notice(n_StatServ, lptr->nick, "Syntax: SERVER <server | mask> [options]"); notice(n_StatServ, lptr->nick, ERR_MORE_INFO, n_StatServ, "SERVER"); return; } hub = NULL; maxusers = -1; minusers = -1; target = NULL; info = 0; /* * Parse their args */ for (ii = 1; ii < ac; ii++) { alen = strlen(av[ii]); if (!ircncmp(av[ii], "-maxusers", alen)) { if (++ii >= ac) { notice(n_StatServ, lptr->nick, "No maximum user count given"); return; } maxusers = atoi(av[ii]); } else if (!ircncmp(av[ii], "-minusers", alen)) { if (++ii >= ac) { notice(n_StatServ, lptr->nick, "No minimum user count given"); return; } minusers = atoi(av[ii]); } else if (!ircncmp(av[ii], "-info", alen)) info = 1; else if (!ircncmp(av[ii], "-hub", alen)) { if (++ii >= ac) { notice(n_StatServ, lptr->nick, "No hub server given"); return; } if (!(hub = FindServer(av[ii]))) { notice(n_StatServ, lptr->nick, "No such server: %s", av[ii]); return; } } else { if (!target) target = av[ii]; } } if (!target) { notice(n_StatServ, lptr->nick, "No target server specified"); return; } argbuf[0] = '\0'; if (maxusers >= 0) { ircsprintf(str, "-maxusers %d ", maxusers); strlcat(argbuf, str, sizeof(argbuf)); } if (minusers >= 0) { ircsprintf(str, "-minusers %d ", minusers); strlcat(argbuf, str, sizeof(argbuf)); } if (info) strlcat(argbuf, "-info ", sizeof(argbuf)); if (hub) { ircsprintf(str, "-hub %s ", hub->name); strlcat(argbuf, str, sizeof(argbuf)); } RecordCommand("%s: %s!%s@%s SERVER [%s] %s", n_StatServ, lptr->nick, lptr->username, lptr->hostname, target, argbuf); if ((servptr = FindServer(target))) { ShowServerInfo(servptr, lptr, 1); return; } cnt = 0; for (servptr = ServerList; servptr; servptr = servptr->next) { if (!match(target, servptr->name)) continue; if (((maxusers >= 0) && (servptr->numusers > maxusers)) || ((minusers >= 0) && (servptr->numusers < minusers))) continue; else if (hub && (servptr->uplink != hub)) continue; /* * servptr passes all the tests */ ++cnt; notice(n_StatServ, lptr->nick, "-----"); ShowServerInfo(servptr, lptr, info); } notice(n_StatServ, lptr->nick, "%d match%s found", cnt, (cnt == 1) ? "" : "es"); } /* ss_server() */
int ss_loaddata() { FILE *fp; char line[MAXLINE + 1], **av; char *keyword; int ac, ret = 1, cnt; if ((fp = fopen(StatServDB, "r")) == NULL) { /* StatServ data file doesn't exist */ return (-1); } cnt = 0; /* load data into list */ while (fgets(line, sizeof(line), fp)) { cnt++; ac = SplitBuf(line, &av); if (!ac) { /* probably a blank line */ MyFree(av); continue; } if (av[0][0] == ';') { MyFree(av); continue; } if (!ircncmp("->", av[0], 2)) { /* * check if there are enough args */ if (ac < 3) { fatal(1, "%s:%d Invalid database format (FATAL)", StatServDB, cnt); ret = -2; MyFree(av); continue; } keyword = av[0] + 2; if (!ircncmp(keyword, "USERS", 5)) { if (Network->TotalUsers <= atol(av[1])) { Network->MaxUsers = atol(av[1]); Network->MaxUsers_ts = atol(av[2]); } } else if (!ircncmp(keyword, "OPERS", 5)) { if (Network->TotalOperators <= atol(av[1])) { Network->MaxOperators = atol(av[1]); Network->MaxOperators_ts = atol(av[2]); } } else if (!ircncmp(keyword, "CHANS", 5)) { if (Network->TotalChannels <= atol(av[1])) { Network->MaxChannels = atol(av[1]); Network->MaxChannels_ts = atol(av[2]); } } else if (!ircncmp(keyword, "SERVS", 5)) { if (Network->TotalServers <= atol(av[1])) { Network->MaxServers = atol(av[1]); Network->MaxServers_ts = atol(av[2]); } } } MyFree(av); } /* while */ fclose(fp); return (ret); } /* ss_loaddata */
static void ss_greplog(struct Luser *lptr, int ac, char **av ) { int day; char buf[MAXLINE + 1]; char date[10]; FILE * lf; char grep_log_filename[MAXLINE + 1]; int i; struct tm * tm; int iCounter; if (ac < 3) { notice(n_StatServ,lptr->nick, "Syntax: \002GREPLOG <service> <pattern> [days]\002"); return; } if (ac > 3 && av[3] != NULL) day = atoi(av[3]); else day = 0; if (day < 0) { notice(n_StatServ, lptr->nick, "Day count should be positive."); return; } if (!GetService(av[1])) { notice(n_StatServ, lptr->nick, "Invalid service!"); return; } iCounter = 0; tm = localtime(¤t_ts); RecordCommand("%s: %s!%s@%s GREPLOG [%s %s] %s", n_StatServ, lptr->nick, lptr->username, lptr->hostname, av[1], av[2], (ac >= 4) ? av[3] : ""); ircsprintf(date, "%4.4d%2.2d%2.2d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); for (i = 0; i <= day; i++) { if (i == 0) ircsprintf(grep_log_filename, "%s/%s", LogPath, LogFile); else ircsprintf(grep_log_filename, "%s/%s.%8.8ld", LogPath, LogFile, korectdat(atol(date), -i)); if ((lf = fopen(grep_log_filename, "r")) == NULL) { notice(n_StatServ, lptr->nick, "No log file: %s", grep_log_filename); continue; } notice(n_StatServ, lptr->nick, "Searching for [%s] with service [%s] for [%d] days in file [%s]", av[2], av[1], day, grep_log_filename); while (fgets(buf, sizeof(buf), lf)) { if ((ircncmp(buf + 25, av[1], strlen(av[1])) == 0) && match(av[2], buf + 25 + strlen(av[1]) + 2)) { iCounter ++; notice(n_StatServ, lptr->nick, "[%d] ... %s", iCounter, buf); } } fclose(lf); } notice(n_StatServ, lptr->nick, "End of search." ); return; } /* o_greplog */
static void ss_clearstats(struct Luser *lptr, int ac, char **av) { int ii, bad; struct HostHash *hosth, *hnext; char buf[MAXLINE + 1], buf2[MAXLINE + 1]; int domain, host; domain = 0; host = 0; if (ac >= 2) { for (ii = 1; ii < ac; ii++) { if (!ircncmp(av[ii], "-domain", strlen(av[ii]))) domain = 1; else if (!ircncmp(av[ii], "-host", strlen(av[ii]))) host = 1; else if (!ircncmp(av[ii], "-all", strlen(av[ii]))) host = domain = 1; } } else { /* * They didn't give an option - delete everything by * default */ host = domain = 1; } buf[0] = '\0'; buf2[0] = '\0'; if (domain && host) { strlcat(buf, "-all", sizeof(buf)); strlcat(buf2, "All", sizeof(buf2)); } else { if (domain) { strlcat(buf, "-domain", sizeof(buf)); strlcat(buf2, "Domains", sizeof(buf2)); } if (host) { strlcat(buf, "-host", sizeof(buf)); strlcat(buf2, "Hostnames", sizeof(buf2)); } } RecordCommand("%s: %s!%s@%s CLEARSTATS %s", n_StatServ, lptr->nick, lptr->username, lptr->hostname, buf); for (ii = 0; ii < HASHCLIENTS; ii++) { bad = 0; hosth = hostTable[ii].list; while (hosth) { if (!domain && (hosth->flags & SS_DOMAIN)) bad = 1; if (!host && !(hosth->flags & SS_DOMAIN)) bad = 1; if (bad) { bad = 0; hosth = hosth->hnext; continue; } hnext = hosth->hnext; MyFree(hosth->hostname); MyFree(hosth); /* * Make sure we set hostTable[ii].list to hnext as well * or it will not be set to NULL at the end of the list, * which could cause big problems */ hostTable[ii].list = hosth = hnext; } } notice(n_StatServ, lptr->nick, "Statistics cleared: %s", buf2); } /* ss_clearstats() */
int ms_loaddata() { FILE *fp; char line[MAXLINE], **av; char *keyword; int ac, ret = 1, cnt; struct MemoInfo *mi = NULL; struct NickInfo *nickptr; if (!(fp = fopen(MemoServDB, "r"))) { /* MemoServ data file doesn't exist */ return -1; } cnt = 0; /* load data into list */ while (fgets(line, MAXLINE - 1, fp)) { cnt++; ac = SplitBuf(line, &av); if (!ac) { /* probably a blank line */ MyFree(av); continue; } if (av[0][0] == ';') { /* its a comment */ MyFree(av); continue; } if (!ircncmp("->", av[0], 2)) { /* * check if there are enough args */ if (ac < 5) { fatal(1, "%s:%d Invalid database format (FATAL)", MemoServDB, cnt); ret = -2; MyFree(av); continue; } /* check if there is no nickname before it */ if (!mi) { fatal(1, "%s:%d No nickname associated with data", MemoServDB, cnt); if (ret > 0) ret = -1; MyFree(av); continue; } keyword = av[0] + 2; if (!ircncmp(keyword, "TEXT", 4)) { struct Memo *memoptr; memoptr = MakeMemo(); memoptr->sender = MyStrdup(av[1]); memoptr->sent = atol(av[2]); memoptr->flags = atol(av[3]); if (!(memoptr->flags & MS_READ)) mi->newmemos++; memoptr->text = MyStrdup(av[4] + 1); memoptr->index = ++mi->memocnt; AddMemo(mi, memoptr); } } /* if (!ircncmp("->", keyword, 2)) */ else { if (mi) { if (!mi->memos) { fatal(1, "%s:%d No memos for entry [%s] (skipping)", MemoServDB, cnt, mi->name); MyFree(mi->name); MyFree(mi); mi = NULL; if (ret > 0) ret = -1; } else AddMemoList(mi); } /* * make sure there are enough args on the line: * <nickname> */ if (ac < 1) { fatal(1, "%s:%d Invalid database format (FATAL)", MemoServDB, cnt); ret = -2; mi = NULL; MyFree(av); continue; } if (!(nickptr = FindNick(av[0]))) { fatal(1, "%s:%d Memo entry [%s] is not a registered nickname (skipping)", MemoServDB, cnt, av[0]); if (ret > 0) ret = -1; mi = NULL; MyFree(av); continue; } #ifdef LINKED_NICKNAMES if (nickptr->master) { /* * nickptr is a leaf nickname - they should not have * memo entries */ fatal(1, "%s:%d Memo entry [%s] is not a master nickname (skipping)", MemoServDB, cnt, av[0]); if (ret > 0) ret = (-1); mi = NULL; MyFree(av); continue; } #endif /* LINKED_NICKNAMES */ mi = MakeMemoList(); mi->name = MyStrdup(av[0]); } MyFree(av); } /* while (fgets(line, MAXLINE - 1, fp)) */ if (mi) { if (!mi->memos) { fatal(1, "%s:%d No memos for entry [%s] (skipping)", MemoServDB, cnt, mi->name); MyFree(mi->name); MyFree(mi); if (ret > 0) ret = -1; } else AddMemoList(mi); } fclose (fp); return (ret); } /* ms_loaddata() */
/* * es_loaddata() * * Load Seen database - return 1 if successful, -1 if not, and -2 if the * errors are unrecoverable */ int es_loaddata() { FILE *fp; char line[MAXLINE], **av; char *keyword; int ac, ret = 1, cnt, type = 0; aSeen *seen; if ((fp = fopen(SeenServDB, "r")) == NULL) { /* SeenServ data file doesn't exist */ return ( -1); } FreeSeen(); cnt = 0; /* load data into list */ while (fgets(line, MAXLINE - 1, fp)) { cnt++; ac = SplitBuf(line, &av); if (!ac) { /* probably a blank line */ MyFree(av); continue; } if (av[0][0] == ';') { MyFree(av); continue; } if (!ircncmp("->", av[0], 2)) { /* * check if there are enough args */ if (ac < 4) { fatal(1, "%s:%d Invalid database format (FATAL)", SeenServDB, cnt); ret = -2; MyFree(av); continue; } keyword = av[0] + 2; type = 0; if (!ircncmp(keyword, "QUIT", 4)) { type = 1; } else if (!ircncmp(keyword, "NICK", 4)) { type = 2; } if (type) { seen = MyMalloc(sizeof(aSeen)); memset(seen, 0, sizeof(aSeen)); strncpy(seen->nick, av[1], NICKLEN); seen->userhost = MyStrdup(av[2]); seen->msg = (type == 1) ? MyStrdup(av[4] + 1) : NULL; seen->time = atol(av[3]); seen->type = type; seen->prev = seenp; seen->next = NULL; if (seenp) seenp->next = seen; seenp = seen; if (!seenb) seenb = seen; ++seenc; } } MyFree(av); } /* while */ fclose(fp); return (ret); } /* es_loaddata */
static void g_gchannote(struct Luser *lptr, int ac, char **av) { int cnt, alen; char *mask; char *message; char argbuf[MAXLINE + 1], temp[MAXLINE + 1]; struct Channel *cptr; if (!GlobalNotices) { notice(n_Global, lptr->nick, "Global notices are disabled"); return; } if (ac < 2) { notice(n_Global, lptr->nick, "Syntax: \002GCHANNOTE [options] <message>\002"); return; } mask = NULL; message = NULL; for (cnt = 1; cnt < ac; ++cnt) { alen = strlen(av[cnt]); if (!ircncmp(av[cnt], "-mask", alen)) { if (++cnt >= ac) { notice(n_Global, lptr->nick, "No mask specified"); return; } mask = av[cnt]; } else { message = GetString(ac - cnt, av + cnt); break; } } if (!message) { notice(n_Global, lptr->nick, "No message specified"); return; } *argbuf = '\0'; if (mask) ircsprintf(argbuf, "-mask %s ", mask); ircsprintf(temp, "%s%s", argbuf, message); strncpy(argbuf, temp, sizeof(argbuf) - 1); argbuf[sizeof(argbuf) - 1] = '\0'; RecordCommand("%s: %s!%s@%s GCHANNOTE %s", n_Global, lptr->nick, lptr->username, lptr->hostname, argbuf); cnt = 0; for (cptr = ChannelList; cptr; cptr = cptr->next) { if (mask && !match(mask, cptr->name)) continue; *temp = '-'; *(temp + 1) = '\0'; if (cptr->modes & MODE_N) strcat(temp, "n"); if (cptr->modes & MODE_M) strcat(temp, "m"); if (*(temp + 1)) DoMode(cptr, temp, 0); notice(n_Global, cptr->name, message); ++cnt; if (*(temp + 1)) { *temp = '+'; DoMode(cptr, temp, 0); } } notice(n_Global, lptr->nick, "Channel message sent (%d match%s)", cnt, (cnt == 1) ? "" : "es"); MyFree(message); } /* g_gchannote() */
static void g_gnote(struct Luser *lptr, int ac, char **av) { int cnt, alen, bad, ii; int all, ops, opers, admins; char *message; char argbuf[MAXLINE + 1]; char temp[MAXLINE * 2]; struct Luser *tempuser; struct Userlist *userptr; if (!GlobalNotices) { notice(n_Global, lptr->nick, "Global notices are disabled"); return; } if (ac < 2) { notice(n_Global, lptr->nick, "Syntax: \002GNOTE [options] <message>\002"); return; } all = 0; ops = 0; opers = 0; admins = 0; message = NULL; for (cnt = 1; cnt < ac; ++cnt) { alen = strlen(av[cnt]); if (!ircncmp(av[cnt], "-all", alen)) all = 1; else if (!ircncmp(av[cnt], "-ops", alen)) ops = 1; else if (!ircncmp(av[cnt], "-opers", alen)) opers = 1; else if (!ircncmp(av[cnt], "-admins", alen)) admins = 1; else { message = GetString(ac - cnt, av + cnt); break; } } if (!message) { notice(n_Global, lptr->nick, "No message specified"); return; } if (!all && !ops && !opers && !admins) all = 1; /* -all is the default */ *argbuf = '\0'; if (all) strcat(argbuf, "-all "); if (ops) strcat(argbuf, "-ops "); if (opers) strcat(argbuf, "-opers "); if (admins) strcat(argbuf, "-admins "); ircsprintf(temp, "%s%s", argbuf, message); strncpy(argbuf, temp, MAXLINE); argbuf[MAXLINE] = '\0'; RecordCommand("%s: %s!%s@%s GNOTE %s", n_Global, lptr->nick, lptr->username, lptr->hostname, argbuf); cnt = 0; for (tempuser = ClientList; tempuser; tempuser = tempuser->next) { if (FindService(tempuser)) continue; if (!ircncmp(Me.name, tempuser->server->name, strlen(tempuser->server->name))) continue; bad = 0; if (!all) { if (opers && !IsOperator(tempuser)) bad = 1; else { if (tempuser->flags & L_OSREGISTERED) ii = 1; else ii = 0; userptr = GetUser(ii, tempuser->nick, tempuser->username, tempuser->hostname); if (ops && !IsOper(userptr)) bad = 1; else if (admins && !IsAdmin(userptr)) bad = 1; } } if (bad) continue; notice(n_Global, tempuser->nick, message); ++cnt; } notice(n_Global, lptr->nick, "Message sent (%d match%s)", cnt, (cnt == 1) ? "" : "es"); MyFree(message); } /* g_gnote() */
void CheckLogs(time_t unixtime) { char tmplog[MAXLINE], olddate[MAXLINE]; char *currdate; struct tm *log_tm; time_t oldts; DIR *dp; struct dirent *dirp; int lmatches, len; if (MaxLogs) { /* * We must now check if there are MaxLogs log files * in HPath/. If so, delete the oldest one to make * room for the current one. */ if (!(dp = opendir(HPath))) { putlog(LOG1, "Error reading log directory: %s", strerror(errno)); return; } ircsprintf(tmplog, "%s.", LogFile); len = strlen(tmplog); lmatches = 0; olddate[0] = '\0'; currdate = NULL; /* * Go through all the files in the directory and * pick out the ones that match "LogFile." */ while ((dirp = readdir(dp))) { if (!ircncmp(dirp->d_name, tmplog, len)) { ++lmatches; /* * Now check the date on the log file to see * if its the oldest. */ if (!*olddate) strcpy(olddate, dirp->d_name + len); else { currdate = dirp->d_name + len; if (atol(olddate) > atol(currdate)) strcpy(olddate, currdate); } } } if ((lmatches >= MaxLogs) && *olddate) { /* * There are too many log files in the directory, * delete the oldest one - it will be: LogFile.olddate */ ircsprintf(tmplog, "%s/%s.%s", HPath, LogFile, olddate); unlink(tmplog); } closedir(dp); } /* if (MaxLogs) */ /* * Now rename the current log file. Use the TS of one * second ago since this log file is actually yesterday's, * because it just turned midnight. */ oldts = unixtime - 1; log_tm = localtime(&oldts); ircsprintf(tmplog, "%s.%d%02d%02d", LogFile, 1900 + log_tm->tm_year, log_tm->tm_mon + 1, log_tm->tm_mday); rename(LogFile, tmplog); } /* CheckLogs() */