diff --git a/Makefile b/Makefile index 219b170..b47bff0 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,9 @@ endif ifeq ($(OS), Darwin) MAKEFILE=Makefile.osx endif - +ifeq ($(OS), SunOS) + MAKEFILE=Makefile.sunos +endif all: magicka .PHONY: magicka www clean cleanwww diff --git a/deps/jamlib/Makefile.sunos b/deps/jamlib/Makefile.sunos new file mode 100644 index 0000000..4ff03b5 --- /dev/null +++ b/deps/jamlib/Makefile.sunos @@ -0,0 +1,29 @@ +CC = gcc $(CPPFLAGS) $(CFLAGS) -D__LINUX__ $(LDFLAGS) -Wall +AR = ar -ru +RM = rm -f + +OBJS = crc32.o mbase.o message.o lastread.o subpack.o structrw.o + +jamlib.a : $(OBJS) + $(AR) jamlib.a $(OBJS) + +crc32.o: crc32.c jam.h + $(CC) -c crc32.c -o crc32.o + +mbase.o: mbase.c jam.h + $(CC) -c mbase.c -o mbase.o + +message.o: message.c jam.h + $(CC) -c message.c -o message.o + +lastread.o: lastread.c jam.h + $(CC) -c lastread.c -o lastread.o + +subpack.o: subpack.c jam.h + $(CC) -c subpack.c -o subpack.o + +structrw.o: structrw.c jam.h + $(CC) -c structrw.c -o structrw.o + +clean: + $(RM) *.o *.a diff --git a/deps/jamlib/mbase.c b/deps/jamlib/mbase.c index 664f0af..5cfd65f 100644 --- a/deps/jamlib/mbase.c +++ b/deps/jamlib/mbase.c @@ -85,6 +85,9 @@ #if defined( __LINUX__ ) #include #include +#ifdef __sun +#include +#endif #endif #define OS_ERROR_OFFSET 10000 diff --git a/deps/libb64-1.2/base64/depend b/deps/libb64-1.2/base64/depend deleted file mode 100644 index e69de29..0000000 diff --git a/deps/libb64-1.2/src/depend b/deps/libb64-1.2/src/depend deleted file mode 100644 index e69de29..0000000 diff --git a/deps/odoors/ODCom.c b/deps/odoors/ODCom.c index 10a6e9a..6d693ba 100644 --- a/deps/odoors/ODCom.c +++ b/deps/odoors/ODCom.c @@ -72,6 +72,9 @@ #include #include #include +#ifdef __sun +#include +#endif #endif #include "ODCore.h" #include "ODGen.h" @@ -1787,7 +1790,16 @@ no_fossil: if (isatty(STDIN_FILENO)) { tcgetattr(STDIN_FILENO,&tio_default); tio_raw = tio_default; +#ifdef __sun + tio_raw.c_iflag &= ~(IMAXBEL|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + tio_raw.c_oflag &= ~OPOST; + tio_raw.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + tio_raw.c_cflag &= ~(CSIZE|PARENB); + tio_raw.c_cflag |= CS8; +#else cfmakeraw(&tio_raw); +#endif + tcsetattr(STDIN_FILENO,TCSANOW,&tio_raw); setvbuf(stdout, NULL, _IONBF, 0); } diff --git a/deps/odoors/OpenDoor.h b/deps/odoors/OpenDoor.h index b0a1252..3502269 100644 --- a/deps/odoors/OpenDoor.h +++ b/deps/odoors/OpenDoor.h @@ -96,7 +96,7 @@ #define OD_DLL #endif /* !OD_WIN32_STATIC */ #else /* !WIN32 */ -#if defined(__unix__) || defined(__NetBSD__) || defined(__APPLE__) +#if defined(__unix__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__sun) #define ODPLAT_NIX #undef ODPLAT_DOS #undef DIRSEP diff --git a/src/Makefile.sunos b/src/Makefile.sunos new file mode 100644 index 0000000..d0789b4 --- /dev/null +++ b/src/Makefile.sunos @@ -0,0 +1,76 @@ +CC=gcc +CFLAGS=-std=gnu99 -I/usr/local/include -I../deps/ +DEPS = bbs.h +JAMLIB = ../deps/jamlib/jamlib.a +ZMODEM = ../deps/Xmodem/libzmodem.a +LUA = ../deps/lua/liblua.a +ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a +JSMN = ../deps/jsmn/libjsmn.a +CDK = ../deps/cdk-5-20161210/libcdk.a + +all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd + +${LUA}: + cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= + +${JAMLIB}: + cd ../deps/jamlib && $(MAKE) -f Makefile.sunos MAKEFLAGS= + +${ZMODEM}: + cd ../deps/Xmodem && $(MAKE) MAKEFLAGS= + +${ODOORS}: + cd ../deps/odoors/ && $(MAKE) + +$(JSMN): + cd ../deps/jsmn/ && $(MAKE) + +$(CDK): + cd ../deps/cdk-5.0-20161210/ && ./configure + cd ../deps/cdk-5.0-20161210/ && $(MAKE) + + +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +magicka: $(OBJ) ${LUA} ${ZMODEM} ${JAMLIB} ${JSMN} + $(CC) -o ../magicka $^ $(CFLAGS) -L/usr/local/lib -lsqlite3 -lm -ldl -lssl -lcrypto -lssh -lnsl -lsocket + +magimail: $(JAMLIB) + cd ../utils/magimail && $(MAKE) freebsd + +magiedit: $(ODOORS) + cd ../utils/magiedit && $(MAKE) -f Makefile.sunos + +ticproc: + cd ../utils/ticproc && $(MAKE) + +mgpost: $(JAMLIB) + cd ../utils/mgpost && $(MAKE) + +magichat: $(JSMN) + cd ../utils/magichat && $(MAKE) -f Makefile.sunos + +fileapprove: $(CDK) + cd ../utils/fileapprove && $(MAKE) + +magiftpd: + cd ../utils/magiftpd && $(MAKE) + +.PHONY: clean + +clean: + rm -f $(OBJ) ../magicka + cd ../deps/lua && $(MAKE) clean + cd ../deps/jamlib && $(MAKE) -f Makefile.linux clean + cd ../deps/Xmodem && $(MAKE) clean + cd ../utils/magimail && $(MAKE) cleanfreebsd + cd ../utils/magiedit && $(MAKE) clean + cd ../deps/odoors/ && rm -rf libs-`uname -s` objs-`uname -s` exe-`uname -s` + cd ../utils/ticproc && $(MAKE) clean + cd ../utils/mgpost && $(MAKE) clean + cd ../utils/magichat && $(MAKE) clean + cd ../deps/cdk-5.0-20161210 && $(MAKE) clean + cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/magiftpd && $(MAKE) clean diff --git a/src/Makefile.sunos.WWW b/src/Makefile.sunos.WWW new file mode 100644 index 0000000..09eb808 --- /dev/null +++ b/src/Makefile.sunos.WWW @@ -0,0 +1,81 @@ +CC=gcc +CFLAGS=-std=gnu99 -I/usr/local/include -I../deps/ -I../deps/libb64-1.2/include -DENABLE_WWW=1 +DEPS = bbs.h +JAMLIB = ../deps/jamlib/jamlib.a +ZMODEM = ../deps/Xmodem/libzmodem.a +LUA = ../deps/lua/liblua.a +B64 = ../deps/libb64-1.2/src/libb64.a +MICROHTTPD=-lmicrohttpd +ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a +JSMN = ../deps/jsmn/libjsmn.a +CDK = ../deps/cdk-5-20161210/libcdk.a + +all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd + +${LUA}: + cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= + +${JAMLIB}: + cd ../deps/jamlib && $(MAKE) -f Makefile.sunos MAKEFLAGS= + +${ZMODEM}: + cd ../deps/Xmodem && $(MAKE) MAKEFLAGS= + +${B64}: + cd ../deps/libb64-1.2 && $(MAKE) MAKEFLAGS= CC=gcc + +${ODOORS}: + cd ../deps/odoors/ && $(MAKE) + +$(JSMN): + cd ../deps/jsmn/ && $(MAKE) + +$(CDK): + cd ../deps/cdk-5.0-20161210/ && ./configure + cd ../deps/cdk-5.0-20161210/ && $(MAKE) + +OBJ = ../deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +magicka: $(OBJ) ${LUA} ${JAMLIB} ${ZMODEM} ${B64} ${JSMN} + $(CC) -o ../magicka $^ $(CFLAGS) -L/usr/local/lib -lsqlite3 -lm -ldl -lssl -lcrypto -lssh $(MICROHTTPD) -lnsl -lsocket + +magimail: $(JAMLIB) + cd ../utils/magimail && $(MAKE) freebsd + +magiedit: $(ODOORS) + cd ../utils/magiedit && $(MAKE) -f Makefile.sunos + +ticproc: + cd ../utils/ticproc && $(MAKE) + +mgpost: $(JAMLIB) + cd ../utils/mgpost && $(MAKE) + +magichat: $(JSMN) + cd ../utils/magichat && $(MAKE) -f Makefile.sunos + +fileapprove: $(CDK) + cd ../utils/fileapprove && $(MAKE) + +magiftpd: + cd ../utils/magiftpd && $(MAKE) + +.PHONY: clean + +clean: + rm -f $(OBJ) ../magicka + cd ../deps/lua && $(MAKE) clean + cd ../deps/jamlib && $(MAKE) -f Makefile.linux clean + cd ../deps/Xmodem && $(MAKE) clean + cd ../deps/libb64-1.2 && $(MAKE) clean + cd ../utils/magimail && $(MAKE) cleanfreebsd + cd ../utils/magiedit && $(MAKE) clean + cd ../deps/odoors/ && rm -rf libs-`uname -s` objs-`uname -s` exe-`uname -s` + cd ../utils/ticproc && $(MAKE) clean + cd ../utils/mgpost && $(MAKE) clean + cd ../utils/magichat && $(MAKE) clean + cd ../deps/cdk-5.0-20161210 && $(MAKE) clean + cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/magiftpd && $(MAKE) clean diff --git a/src/doors.c b/src/doors.c index 0e16804..cb45a3e 100644 --- a/src/doors.c +++ b/src/doors.c @@ -14,8 +14,10 @@ # include #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include -#else +#elif defined(__FreeBSD__) # include +#elif defined(__sun) +# include "os/sunos.h" #endif #include "bbs.h" #include "lua/lua.h" diff --git a/src/files.c b/src/files.c index f8bde6d..b8b5f20 100644 --- a/src/files.c +++ b/src/files.c @@ -576,7 +576,12 @@ int do_upload(struct user_record *user, char *final_path) { return 0; } while ((dent = readdir(inb)) != NULL) { +#ifdef __sun + stat(dent->d_name, &s); + if (S_ISREG(s.st_mode)) { +#else if (dent->d_type == DT_REG) { +#endif snprintf(upload_command, 1024, "%s%s", upload_path, dent->d_name); snprintf(upload_filename, 1024, "%s/%s", final_path, dent->d_name); diff --git a/src/mail_menu.c b/src/mail_menu.c index f064ca6..23107aa 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -13,7 +13,9 @@ #include "lua/lua.h" #include "lua/lualib.h" #include "lua/lauxlib.h" - +#ifdef __sun +#include "os/sunos.h" +#endif extern struct bbs_config conf; extern struct user_record *gUser; extern int mynode; @@ -24,8 +26,11 @@ time_t utc_to_local(time_t utc) { localtime_r(&utc, &date_time); +#ifdef __sun + local = utc + gmtoff(utc); +#else local = utc + date_time.tm_gmtoff; - +#endif return local; } diff --git a/src/main.c b/src/main.c index 9e6c686..108fced 100644 --- a/src/main.c +++ b/src/main.c @@ -17,10 +17,12 @@ #include #if defined(linux) # include -#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include -#else +#elif defined(__FreeBSD__) # include +#elif defined(__sun) +# include "os/sunos.h" #endif #if defined(ENABLE_WWW) # include diff --git a/src/os/sunos.c b/src/os/sunos.c new file mode 100644 index 0000000..6e4a62e --- /dev/null +++ b/src/os/sunos.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include +#define TM_YEAR_ORIGIN 1900 + +int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) { + int ptm; + char *pname; + int pts; + + ptm = open("/dev/ptmx", O_RDWR); + + grantpt(ptm); + unlockpt(ptm); + + pname = ptsname(ptm); + + if (name != NULL) { + strcpy(name, pname); + } + + pts = open(name, O_RDWR); + ioctl(pts, I_PUSH, "ptem"); + ioctl(pts, I_PUSH, "ldterm"); + ioctl(pts, I_PUSH, "ttcompat"); + + if (termp != NULL) { + tcsetattr(pts, TCSAFLUSH, termp); + } + if (winp != NULL) { + ioctl(pts, TIOCSWINSZ, winp); + } + + + *amaster = ptm; + *aslave = pts; + + return 0; +} + +int forkpty(int *amaster, char *name, void *termp, void *winp) { + + int ptm; + char *pname; + int pts; + pid_t pid; + + ptm = open("/dev/ptmx", O_RDWR); + + grantpt(ptm); + unlockpt(ptm); + + pname = ptsname(ptm); + + if (name != NULL) { + strcpy(name, pname); + } + pts = open(name, O_RDWR); + ioctl(pts, I_PUSH, "ptem"); + ioctl(pts, I_PUSH, "ldterm"); + ioctl(pts, I_PUSH, "ttcompat"); + + if (termp != NULL) { + tcsetattr(pts, TCSAFLUSH, termp); + } + if (winp != NULL) { + ioctl(pts, TIOCSWINSZ, winp); + } + + pid = fork(); + + if (!pid) { + close(ptm); + dup2(pts, 0); + dup2(pts, 1); + dup2(pts, 2); + close(pts); + } else { + *amaster = ptm; + } + + return pid; +} + + +static long difftm(struct tm *a, struct tm *b) { + int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); + int by = b->tm_year + (TM_YEAR_ORIGIN - 1); + long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by/100) + ((ay/100 >> 2) - (by / 100 >> 2)) + (long)(ay-by) * 365); + + return (60 * (60 * (24 *days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec)); +} + +long gmtoff(time_t value) { + struct tm gmt = *gmtime(&value); + return difftm(localtime(&value), &gmt); +} diff --git a/src/os/sunos.h b/src/os/sunos.h new file mode 100644 index 0000000..42950ed --- /dev/null +++ b/src/os/sunos.h @@ -0,0 +1,8 @@ +#ifndef __SUNOS_H +#define __SUNOS_H + +extern int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp); +extern int forkpty(int *amaster, char *name, void *termp, void *winp); +extern long gmtoff(time_t value); +#endif + diff --git a/src/www_msgs.c b/src/www_msgs.c index 6daba62..29fcc45 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -4,9 +4,7 @@ #include #include #include -#ifdef __FreeBSD__ #include -#endif #include "bbs.h" #include "jamlib/jam.h" diff --git a/utils/fileapprove/Makefile b/utils/fileapprove/Makefile index 9f42dbd..a4b59b3 100644 --- a/utils/fileapprove/Makefile +++ b/utils/fileapprove/Makefile @@ -3,31 +3,34 @@ OS := $(shell uname -s) ifeq ($(OS), FreeBSD) CC=cc CFLAGS=-I/usr/local/include - LDFLAGS=-L/usr/local/lib + LDFLAGS=-L/usr/local/lib -lsqlite3 -lncurses endif ifeq ($(OS), DragonFly) CC=cc CFLAGS=-I/usr/local/include -I/usr/local/include/ncurses - LDFLAGS=-L/usr/local/lib + LDFLAGS=-L/usr/local/lib -lsqlite3 -lncurses endif ifeq ($(OS), NetBSD) CC=cc CFLAGS=-I/usr/pkg/include - LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib + LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib -lsqlite3 -lncurses endif ifeq ($(OS), Linux) CC=gcc CFLAGS= - LDFLAGS= + LDFLAGS=-lsqlite3 -lncurses endif ifeq ($(OS), Darwin) CC=cc CFLAGS= - LDFLAGS= + LDFLAGS=-lsqlite3 -lncurses +endif +ifeq ($(OS), SunOS) + CC=gcc + CFLAGS= + LDFLAGS=-lsqlite3 -lcurses endif - -CC=cc DEPS = fileapprove.c OBJ = fileapprove.o @@ -35,7 +38,7 @@ OBJ = fileapprove.o $(CC) -c -o $@ $< $(CFLAGS) -I../../deps/cdk-5.0-20161210/include/ fileapprove: $(OBJ) - $(CC) -o fileapprove -o $@ $^ ../../deps/cdk-5.0-20161210/libcdk.a $(CFLAGS) $(LDFLAGS) -lsqlite3 -lncurses + $(CC) -o fileapprove -o $@ $^ ../../deps/cdk-5.0-20161210/libcdk.a $(CFLAGS) $(LDFLAGS) .PHONY: clean diff --git a/utils/magichat/Makefile.sunos b/utils/magichat/Makefile.sunos new file mode 100644 index 0000000..255b0b2 --- /dev/null +++ b/utils/magichat/Makefile.sunos @@ -0,0 +1,22 @@ +CC=cc + +DEPS = main.c + +OBJ = main.o +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +JSMN = ../../deps/jsmn/libjsmn.a + +all: magichat + +$(JSMN): + cd ../../deps/jsmn/ && $(MAKE) + +magichat: $(OBJ) $(JSMN) + $(CC) -o magichat -o $@ $^ $(CFLAGS) $(LDFLAGS) -lsocket + +.PHONY: clean + +clean: + rm -f $(OBJ) magichat diff --git a/utils/magiedit/Makefile.sunos b/utils/magiedit/Makefile.sunos new file mode 100644 index 0000000..800db2c --- /dev/null +++ b/utils/magiedit/Makefile.sunos @@ -0,0 +1,22 @@ +CC=cc +CFLAGS=-I../../deps/odoors/ +DEPS = main.c +ODOORS = ../../deps/odoors/libs-`uname -s`/libODoors.a + +OBJ = main.o + +all: magiedit + +${ODOORS}: + cd ../../deps/odoors && $(MAKE) MAKEFLAGS= + +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +magiedit: $(OBJ) $(ODOORS) + $(CC) -o magiedit -o $@ $^ $(CFLAGS) $(ODOORS) -lsocket + +.PHONY: clean + +clean: + rm -f $(OBJ) magiedit diff --git a/utils/magiftpd/Makefile b/utils/magiftpd/Makefile index 1775397..c08e98b 100644 --- a/utils/magiftpd/Makefile +++ b/utils/magiftpd/Makefile @@ -3,29 +3,33 @@ OS := $(shell uname -s) ifeq ($(OS), FreeBSD) CC=cc CFLAGS=-I/usr/local/include - LDFLAGS=-L/usr/local/lib + LDFLAGS=-L/usr/local/lib -lsqlite3 -lcrypto endif ifeq ($(OS), DragonFly) CC=cc CFLAGS=-I/usr/local/include - LDFLAGS=-L/usr/local/lib + LDFLAGS=-L/usr/local/lib -lsqlite3 -lcrypto endif ifeq ($(OS), NetBSD) CC=cc CFLAGS=-I/usr/pkg/include - LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib + LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib -lsqlite3 -lcrypto endif ifeq ($(OS), Linux) CC=gcc CFLAGS= - LDFLAGS= + LDFLAGS=-lsqlite3 -lcrypto endif ifeq ($(OS), Darwin) CC=cc CFLAGS=-I/opt/local/include - LDFLAGS=-L/opt/local/lib + LDFLAGS=-L/opt/local/lib -lsqlite3 -lcrypto +endif +ifeq ($(OS), SunOS) + CC=gcc + CFLAGS= + LDFLAGS=-lsqlite3 -lcrypto -lsocket -lnsl endif - DEPS = magiftpd.c @@ -35,7 +39,7 @@ OBJ = magiftpd.o ../../src/inih/ini.o magiftpd: $(OBJ) - $(CC) -o magiftpd -o $@ $^ $(CFLAGS) $(LDFLAGS) -lsqlite3 -lcrypto + $(CC) -o magiftpd $^ $(CFLAGS) $(LDFLAGS) .PHONY: clean diff --git a/utils/magimail/src/Makefile.linux b/utils/magimail/src/Makefile.linux index 5b6b2c2..5605258 100644 --- a/utils/magimail/src/Makefile.linux +++ b/utils/magimail/src/Makefile.linux @@ -39,6 +39,12 @@ MBOBJS = $(MBOBJS_MSG) $(MBOBJS_JAM) $(MBOBJS_SQ3) DEFS = $(PLATFORMDEF) $(MBDEFS) $(NLDEFS) +ifeq ($(OS), SunOS) + SLIBS = -lsocket -lnsl +else + SLIBS = +endif + # Commands ifeq ($(OS), $(filter $(OS), FreeBSD DragonFly)) CC = cc $(CPPFLAGS) $(CFLAGS) $(DEFS) $(LDFLAGS) -L/usr/local/lib -I $(INCDIR) -I ../../../deps/ -I/usr/local/include -Wall @@ -88,7 +94,7 @@ files : $(BINDIR)/magimail$(EXESUFFIX) \ $(BINDIR)/magilistout$(EXESUFFIX) $(BINDIR)/magimail$(EXESUFFIX) : $(CMOBJS) $(SHOBJS) $(NLOBJS) $(MBOBJS) $(OSLIB) - $(CC) -o $(BINDIR)/magimail$(EXESUFFIX) $(CMOBJS) $(SHOBJS) $(NLOBJS) $(MBOBJS) $(OSLIB) -lsqlite3 + $(CC) -o $(BINDIR)/magimail$(EXESUFFIX) $(CMOBJS) $(SHOBJS) $(NLOBJS) $(MBOBJS) $(OSLIB) -lsqlite3 $(SLIBS) $(STRIP) $(BINDIR)/magimail$(EXESUFFIX) $(BINDIR)/magistats$(EXESUFFIX) : tools/magistats.c $(SHOBJS) $(OSLIB)