Commit 4e82e903 authored by Andrew Price's avatar Andrew Price
Browse files

Decouple mwlog() from the client

Should make it simpler to move logging into the server.
parent dd42a192
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -10,10 +10,6 @@
#define HOMEPATH	"/usr/local/lib/mw"
#endif

#ifndef LOGDIR
#define LOGDIR		"/var/log/mw"
#endif

#ifndef STATEDIR
#define STATEDIR	"/var/lib/mw"
#endif
@@ -22,7 +18,6 @@
#define MSGDIR		"/run/mw"
#endif

#define LOGFILE		LOGDIR"/log.bb"
#define LOGIN_BANNER    HOMEPATH"/login.banner"
#define LOCKFILE	"/tmp/bb.locked"
#define EDITOR		"/usr/bin/vim"
@@ -41,7 +36,6 @@
#define CMD_TALK_STR	"."
#define CMD_SCRIPT_STR	","

#define LOGLINESIZE	2048	/* size of a line printed to log file */
#define MAXTEXTLENGTH	2048	/* text buffer size */
#define MAXPIPELENGTH	4096	/* maximum length of a pipe message */

+22 −21
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <signal.h>

#include <util.h>
#include <mwlog.h>
#include "talker_privs.h"
#include "special.h"
#include "incoming.h"
@@ -189,7 +190,7 @@ void edit_user(const char *args, const char *name)
			ipc_send_to_username(usr->name, IPC_STATUS, stats);
			show_change(oldstats, statout, "%s has just changed %s's status",
			            user->record.name, usr->name);
			mwlog("CHANGE(STATUS) of %s by %s", usr->name, stats);
			mwlog(user, "CHANGE(STATUS) of %s by %s", usr->name, stats);
		}
		free(oldstats);
	}else
@@ -213,7 +214,7 @@ void edit_user(const char *args, const char *name)
			ipc_send_to_username(usr->name, IPC_SPECIAL, stats);
			show_change(oldstats, statout, "%s has just changed %s's specials",
			            user->record.name, usr->name);
			mwlog("CHANGE(SPECIAL) of %s by %s", usr->name, stats);
			mwlog(user, "CHANGE(SPECIAL) of %s by %s", usr->name, stats);
		}
		free(oldstats);
	}else
@@ -234,7 +235,7 @@ void edit_user(const char *args, const char *name)
			show_change(oldstats, display_cpflags(usr->chatprivs),
			           "%s has just changed %s's chatprivs",
			           user->record.name, usr->name);
			mwlog("CHANGE(CHATPRIV) of %s by %s", usr->name, stats);
			mwlog(user, "CHANGE(CHATPRIV) of %s by %s", usr->name, stats);
		}
		free(oldstats);
	}else
@@ -269,7 +270,7 @@ void edit_user(const char *args, const char *name)

			broadcast(3, "%s has just changed %s's protection from %s to %d/%d.",
			         user->record.name, usr->name, oldstats, cpl, apl);
			mwlog("CHANGE(PROTLEVEL) of %s to %d/%d", usr->name, cpl, apl);
			mwlog(user, "CHANGE(PROTLEVEL) of %s to %d/%d", usr->name, cpl, apl);
		} else if (*stats)
		{
			printf(_("Invalid protection level.\n"));
@@ -295,7 +296,7 @@ void edit_user(const char *args, const char *name)
			            user->record.name, usr->name);
			if (*stats)
			{
				mwlog("CHANGE(CHATMODE) of %s by %s", usr->name, stats);
				mwlog(user, "CHANGE(CHATMODE) of %s by %s", usr->name, stats);
			}
		}
		free(oldstats);
@@ -314,7 +315,7 @@ void edit_user(const char *args, const char *name)
		{
			usr->groups = folder_groups(stats, usr->groups);
			ipc_send_to_username(usr->name, IPC_GROUPS, stats);
			mwlog("CHANGE(GROUPS) of %s by %s", usr->name, stats);
			mwlog(user, "CHANGE(GROUPS) of %s by %s", usr->name, stats);

			show_fold_groups(usr->groups, stats, false);
			show_change(oldstats, stats, "%s has just changed %s's groups",
@@ -339,7 +340,7 @@ void edit_user(const char *args, const char *name)
			strcpy(usr->passwd, pass1);
			printf(_("Password changed.\n"));
			broadcast(3, "%s has just changed %s's password.", user->record.name, usr->name);
			mwlog("CHANGE(PASSWD) of %s", usr->name);
			mwlog(user, "CHANGE(PASSWD) of %s", usr->name);
			ipc_send_to_username(usr->name, IPC_PASSWD, usr->passwd);
		}
	}else
@@ -359,7 +360,7 @@ void edit_user(const char *args, const char *name)
			printf(_("New name set.\n"));
			broadcast(3, "%s has just changed %s's realname from \"%s\" to \"%s\".",
			          user->record.name, usr->name, oldreal, realname);
			mwlog("CHANGE(REALNAME) of %s to %s", usr->name, realname);
			mwlog(user, "CHANGE(REALNAME) of %s to %s", usr->name, realname);
		}
		free(oldreal);
	}else
@@ -393,7 +394,7 @@ void edit_user(const char *args, const char *name)
			printf(_("Room changed to %d.\n"), usr->room);
			broadcast(3, "%s has just changed %s's room from %d to %d.",
			          user->record.name, usr->name, oldroom, newroom);
			mwlog("CHANGE(ROOM) of %s to %d", usr->name, newroom);
			mwlog(user, "CHANGE(ROOM) of %s to %d", usr->name, newroom);
		}
	}else
	if (stringcmp(args,"username",1))
@@ -435,7 +436,7 @@ void edit_user(const char *args, const char *name)
				printf(_("New name set.\n"));
				broadcast(3, "%s has just renamed %s to %s.",
				          user->record.name, oldname, username);
				mwlog("CHANGE(USERNAME) of %s to %s", oldname, username);
				mwlog(user, "CHANGE(USERNAME) of %s to %s", oldname, username);
			}else
				printf(_("Change cancelled.\n"));
		}else
@@ -454,7 +455,7 @@ void edit_user(const char *args, const char *name)
			printf(_("New address set.\n"));
			broadcast(3, "%s has just changed %s's contact to %s.",
			          user->record.name, usr->name, contact);
			mwlog("CHANGE(CONTACT) of %s to %s", usr->name, contact);
			mwlog(user, "CHANGE(CONTACT) of %s to %s", usr->name, contact);
		}
	}else
	if (stringcmp(args,"doing",2))
@@ -471,14 +472,14 @@ void edit_user(const char *args, const char *name)
			printf(_("New status set.\n"));
			broadcast(3, "%s has just changed %s's status to %s.",
			          user->record.name, usr->name, doing);
			mwlog("CHANGE(STATUS) of %s to %s", usr->name, doing);
			mwlog(user, "CHANGE(STATUS) of %s to %s", usr->name, doing);
		} else {
			*(usr->doing) = 0;
			usr->dowhen = 0;
			ipc_send_to_username(usr->name, IPC_DOING, usr->doing);
			printf(_("New status set.\n"));
			broadcast(3, "%s has just cleared %s's status.", user->record.name, usr->name);
			mwlog("CHANGE(STATUS) cleared %s", doing);
			mwlog(user, "CHANGE(STATUS) cleared %s", doing);
		}
	}else
	if (stringcmp(args,"timeout",1))
@@ -511,7 +512,7 @@ void edit_user(const char *args, const char *name)
					printf(_("TIMEOUT now disabled.\n"));
					broadcast(3, "%s has just disabled %s's timeout.",
					         user->record.name, usr->name);
					mwlog("CHANGE(TIMEOUT) of %s to disabled", usr->name);
					mwlog(user, "CHANGE(TIMEOUT) of %s to disabled", usr->name);
				}
				else
				{
@@ -530,7 +531,7 @@ void edit_user(const char *args, const char *name)
				broadcast(3, "%s has just changed %s's timeout to %"PRId32" seconds.",
				          user->record.name, usr->name, usr->timeout);
				printf(_("New timeout set to %"PRId32" seconds.\n"), usr->timeout);
				mwlog("CHANGE(TIMEOUT) of %s to %"PRId32" seconds", usr->name, usr->timeout);
				mwlog(user, "CHANGE(TIMEOUT) of %s to %"PRId32" seconds", usr->name, usr->timeout);
			}
		}
	}else
@@ -667,7 +668,7 @@ void edit_folder(const char *args, const char *name)
				printf(_("WARNING: folder may get written over by the next folder created.\n"));
		}
		log[255] = '\0';
		mwlog("%s", log);
		mwlog(user, "%s", log);
	}else
	if (stringcmp(args,"groups",2))
	{
@@ -678,7 +679,7 @@ void edit_folder(const char *args, const char *name)
		if (*tmp)
		{
			fold.groups=folder_groups(tmp,fold.groups);
			mwlog("FOLDER(GROUPS) of %s by %s", fold.name, tmp);
			mwlog(user, "FOLDER(GROUPS) of %s by %s", fold.name, tmp);
			show_fold_groups(fold.groups,tmp,true);
			printf(_("Groups changed to [%s]\n"),tmp);
		}
@@ -691,7 +692,7 @@ void edit_folder(const char *args, const char *name)
		if (*tmp == '\0' || strchr(tmp, '/') != NULL) {
			printf("Bad folder name\n");
		} else {
			mwlog("FOLDER(RENAME) of %s to %s", fold.name, tmp);
			mwlog(user, "FOLDER(RENAME) of %s to %s", fold.name, tmp);
			if (rename_folder(&fold, tmp) == 0)
				printf(_("Name changed to %s\n"), fold.name);
		}
@@ -737,7 +738,7 @@ void edit_folder(const char *args, const char *name)
		{
			strcpy(fold.topic,tmp);
			printf(_("Topic changed to '%s'\n"),fold.topic);
			mwlog("FOLDER(TOPIC) of %s to %s", fold.name, tmp);
			mwlog(user, "FOLDER(TOPIC) of %s to %s", fold.name, tmp);
		}
	}else
	if (stringcmp(args,"delete",6))
@@ -756,7 +757,7 @@ void edit_folder(const char *args, const char *name)
			fold.name[0]=0;
			users_lastread(folnum);
			printf(_("Folder deleted.\n"));
			mwlog("FOLDER(DELETE) %s", fold.name);
			mwlog(user, "FOLDER(DELETE) %s", fold.name);
		}else
		{
			printf(_("Not done.\n"));
@@ -977,7 +978,7 @@ void edit_contact(void)
		strcpy(user->record.contact, contact);
		printf(_("New address set.\n"));
		broadcast(3, "Contact for %s has just changed to %s.", user->record.name, contact);
		mwlog("CHANGE(CONTACT) of %s to %s", user->record.name, contact);
		mwlog(user, "CHANGE(CONTACT) of %s to %s", user->record.name, contact);
	}
	update_user(user);
}
+5 −1
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include <mwlog.h>
#include "ipc.h"
#include "files.h"
#include "perms.h"
@@ -17,6 +19,8 @@
#include "folders.h"
#include "mesg.h"

extern struct user * const user;

void add_folder(void)
{
	struct folder new;
@@ -70,7 +74,7 @@ void add_folder(void)
	}
	Unlock_File(file);
	close(file);
	mwlog("FOLDER(CREATED) %s", new.name);
	mwlog(user, "FOLDER(CREATED) %s", new.name);
}

void auto_subscribe(int folnum, int state)
+9 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <netinet/in.h>
#include <signal.h>

#include <mwlog.h>
#include "command.h"
#include "alarm.h"
#include "strings.h"
@@ -193,12 +194,12 @@ static void accept_line(char *line)
	{
		*comm=0;
		eof_count++;
		mwlog("EOF");
		mwlog(user, "EOF");
		if (eof_count>3)
		{
			broadcast(1, "\03304%s'%s connection has just dropped.", user->record.name,
			          user->record.name[strlen(user->record.name)] == 's' ? "" : "s");
			mwlog("EOF(LOGOUT)");
			mwlog(user, "EOF(LOGOUT)");
			close_down(LOGOFF_EOFS, NULL, NULL);
		}
	} else
@@ -650,9 +651,9 @@ int main(int argc, char **argv)
		ss=sizeof(sa);
		/* can we log a hostname ? */
		if (getpeername(fileno(stdin), (struct sockaddr *)&sa, &ss))
			mwlog("LOGIN");
			mwlog(user, "LOGIN");
		else
			mwlog("LOGIN from %s", inet_ntoa(sa.sin_addr));
			mwlog(user, "LOGIN from %s", inet_ntoa(sa.sin_addr));
	}

	time_t when = user->record.lastlogout;
@@ -758,7 +759,7 @@ int main(int argc, char **argv)
			printf("<%d>\n", busy);
			fflush(stdout);
			perror("stdin");
			mwlog("ERROR on stdin");
			mwlog(user, "ERROR on stdin");
			close_down(LOGOFF_ERROR, NULL, NULL);
		}
		if (!busy && MesgIsStacked())
@@ -909,7 +910,7 @@ void close_down(int logofftype, char *sourceuser, char *reason)
	if (!quietmode && logofftype != LOGOFF_TIMEOUT && logofftype != LOGOFF_EOFS)
		broadcast(1, "\03302%s has just left the board.", user->record.name);

	mwlog("LOGOUT");
	mwlog(user, "LOGOUT");
	sleep(1); //dodgy hack for race condition in checkonoff, cunningly we currently get woken by the very message we're waiting for.

	ipc_close();
@@ -1259,7 +1260,7 @@ static void time_out(void *idle_count_p)
		write(1,msg,strlen(msg));

		broadcast(1, _("\03304%s has been timed out."), user->record.name);
		mwlog("TIMEOUT(LOGOUT)");
		mwlog(user, "TIMEOUT(LOGOUT)");
		close_down(LOGOFF_TIMEOUT, NULL, NULL);
	}
	else if (*icnt==0)
@@ -1272,7 +1273,7 @@ static void time_out(void *idle_count_p)
	}
	else
	{
		mwlog("TIMEOUT(BLOCKED)");
		mwlog(user, "TIMEOUT(BLOCKED)");
		close_down(LOGOFF_TIMEOUT, NULL, NULL);
	}

+5 −32
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <sys/stat.h>

#include <util.h>
#include <mwlog.h>
#include "talker_privs.h"
#include "special.h"
#include "ipc.h"
@@ -63,10 +64,10 @@ void broadcast(int state, const char *fmt, ...)
	israw = (state & 0x100) != 0;
	state &= ~0x100;

	if (state==0) mwlog("WALL %s", text);
	else if (state==1 && israw) mwlog("BROADCAST %s", text);
	else if (state==2) mwlog("WIZ %s", text);
	else if (state==5) mwlog("STATUS %s", text);
	if (state==0) mwlog(user, "WALL %s", text);
	else if (state==1 && israw) mwlog(user, "BROADCAST %s", text);
	else if (state==2) mwlog(user, "WIZ %s", text);
	else if (state==5) mwlog(user, "STATUS %s", text);

	switch (state) {
		case 1:
@@ -102,31 +103,3 @@ void broadcast(int state, const char *fmt, ...)
			ipc_send_to_all(IPC_TEXT, buff);
	}
}

void mwlog(const char *fmt, ...)
{
	char detail[LOGLINESIZE];
	mode_t mask;
	va_list ap;
	time_t t;
	char *ts;
	FILE *fp;

	mask = umask(077);
	fp = fopen(LOGFILE, "a");
	umask(mask);
	if (fp == NULL) {
		perror(LOGFILE);
		return;
	}
	t=time(0);
	ts = asctime(gmtime(&t));
	if (ts != NULL && *ts != '\0')
		ts[strlen(ts) - 1] = '\0';
	va_start(ap, fmt);
	vsnprintf(detail, LOGLINESIZE-1, fmt, ap);
	va_end(ap);
	fprintf(fp, "%s | %*s | %s\n", ts, NAMESIZE, user->record.name, detail);
	fclose(fp);
}
Loading