├── AUTHORS ├── vs13 ├── lib │ ├── x64 │ │ └── json-c.lib │ └── x86 │ │ └── json-c.lib ├── collabreate.sln └── collabreate.vcxproj.filters ├── vs17 ├── lib │ └── x64 │ │ └── json-c.lib ├── collabreate.sln └── collabreate.vcxproj.filters ├── json-c ├── json_config.h ├── strerror_override_private.h ├── strdup_compat.h ├── json_inttypes.h ├── random_seed.h ├── strerror_override.h ├── math_compat.h ├── bits.h ├── json.h ├── snprintf_compat.h ├── vasprintf_compat.h ├── json_c_version.h ├── json_object_private.h ├── arraylist.h ├── debug.h ├── json_util.h ├── json_visit.h ├── printbuf.h ├── json_pointer.h ├── config.h ├── json_tokener.h └── json_object_iterator.h ├── .gitignore ├── server ├── java │ └── collabreate │ │ └── server │ │ ├── launch_manager.sh │ │ ├── manager_manifest.mf │ │ ├── server_manifest.mf │ │ ├── launch_server.sh │ │ ├── my_server.conf │ │ ├── collabctl.7 │ │ ├── ProjectInfo.java │ │ ├── build_jar.sh │ │ ├── HmacMD5.java │ │ ├── LICENSE │ │ ├── collabreate_server.7 │ │ ├── collabreate_manager.7 │ │ ├── install_server.sh │ │ ├── collabctl │ │ ├── ubuntu-init.d-script │ │ ├── Utils.java │ │ ├── fedora-init.d-script │ │ ├── dbUtils.java │ │ └── README ├── c++ │ ├── Makefile │ ├── clientset.h │ ├── projectmap.h │ ├── clientset.cpp │ ├── proj_info.cpp │ ├── proj_info.h │ ├── io.h │ ├── db_mgr.h │ ├── mgr_helper.h │ ├── projectmap.cpp │ ├── cli_mgr.cpp │ ├── server_mgr.h │ └── server.cpp └── server.json ├── database ├── postgresql │ ├── dbclean.sql │ └── dbschema.sql ├── mysql │ ├── dbclean.sql │ └── dbschema.sql └── init_database.sh ├── idanet.h ├── collabreate_ui.h ├── ChangeLog ├── Makefile └── README /AUTHORS: -------------------------------------------------------------------------------- 1 | Chris Eagle, cseagle at gmail d0t c0m 2 | Tim Vidas, tvidas at gmail d0t c0m 3 | -------------------------------------------------------------------------------- /vs13/lib/x64/json-c.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseagle/collabREate/HEAD/vs13/lib/x64/json-c.lib -------------------------------------------------------------------------------- /vs13/lib/x86/json-c.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseagle/collabREate/HEAD/vs13/lib/x86/json-c.lib -------------------------------------------------------------------------------- /vs17/lib/x64/json-c.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseagle/collabREate/HEAD/vs17/lib/x64/json-c.lib -------------------------------------------------------------------------------- /json-c/json_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* Define to 1 if you have the header file. */ 3 | #if defined(_MSC_VER) && _MSC_VER >= 1800 4 | #define JSON_C_HAVE_INTTYPES_H 1 5 | #endif 6 | -------------------------------------------------------------------------------- /json-c/strerror_override_private.h: -------------------------------------------------------------------------------- 1 | #ifndef __json_strerror_override_private_h__ 2 | #define __json_strerror_override_private_h__ 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | /* Used by tests to get consistent output */ 10 | extern int _json_c_strerror_enable; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | 5 | # Object files 6 | *.o 7 | *.ko 8 | *.obj 9 | *.elf 10 | 11 | # Libraries 12 | *.lai 13 | *.la 14 | *.lib 15 | *.a 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | -------------------------------------------------------------------------------- /server/java/collabreate/server/launch_manager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #the CLASSPATH should already be setup in the jar file, if not 4 | #you can try something like: 5 | #CLASSPATH=mysql-connector-java-5.1.13-bin.jar:postgresql-9.0-801.jdbc4.jar 6 | #java -classpath $CLASSPATH -jar collabreate_manager.jar $1 7 | 8 | java -jar collabreate_manager.jar server.json 9 | 10 | -------------------------------------------------------------------------------- /json-c/strdup_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __strdup_compat_h 2 | #define __strdup_compat_h 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | #if !defined(HAVE_STRDUP) && defined(_MSC_VER) 10 | /* MSC has the version as _strdup */ 11 | # define strdup _strdup 12 | #elif !defined(HAVE_STRDUP) 13 | # error You do not have strdup on your system. 14 | #endif /* HAVE_STRDUP */ 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /database/postgresql/dbclean.sql: -------------------------------------------------------------------------------- 1 | -- use to drop the collabreate db, something like: 2 | -- psql -U collab collabDB 3 | -- psql> \i dbclean.sql 4 | DROP TABLE tracker; 5 | DROP TABLE forklist; 6 | DROP TABLE snapshots; 7 | DROP SEQUENCE snapshots_sid_seq; 8 | DROP TABLE updates; 9 | DROP SEQUENCE updates_updateid_seq; 10 | DROP TABLE tablename; 11 | DROP TABLE projects; 12 | DROP SEQUENCE projects_pid_seq; 13 | DROP TABLE users; 14 | DROP LANGUAGE plpgsql cascade; 15 | -------------------------------------------------------------------------------- /json-c/json_inttypes.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file 4 | * @brief Do not use, json-c internal, may be changed or removed at any time. 5 | */ 6 | #ifndef _json_inttypes_h_ 7 | #define _json_inttypes_h_ 8 | 9 | #include "json_config.h" 10 | 11 | #ifdef JSON_C_HAVE_INTTYPES_H 12 | /* inttypes.h includes stdint.h */ 13 | #include 14 | 15 | #else 16 | #include 17 | 18 | #define PRId64 "I64d" 19 | #define SCNd64 "I64d" 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /database/mysql/dbclean.sql: -------------------------------------------------------------------------------- 1 | -- use to drop the collabreate db, something like: 2 | -- mysql collabDB < my_dbclean.sql 3 | 4 | use collabDB; 5 | 6 | DROP TABLE forklist; 7 | DROP TABLE updates; 8 | DROP TABLE projects; 9 | DROP TABLE users; 10 | DROP TABLE updateid; 11 | DROP FUNCTION nextid; 12 | DROP FUNCTION insertUpdate; 13 | DROP PROCEDURE copyUpdates; 14 | DROP FUNCTION addUserQuery; 15 | DROP FUNCTION addProjectQuery; 16 | DROP FUNCTION addProjectSnapQuery; 17 | DROP FUNCTION addProjectForkQuery; 18 | 19 | -------------------------------------------------------------------------------- /server/java/collabreate/server/manager_manifest.mf: -------------------------------------------------------------------------------- 1 | Main-Class: collabreate.server.ServerManager 2 | Class-Path: mysql-connector-java-5.1.13-bin.jar postgresql-9.0-801.jdbc4.jar 3 | Name: collabreate/server/CollabreateServer/ 4 | Specification-Title: CollabREate Server 5 | Specification-Version: 0.4.0 6 | Specification-Vendor: Chris Eagle & Tim Vidas. 7 | Implementation-Title: CollabREate Server 8 | Implementation-Version: Ida Qt 9 | Implementation-Vendor: Chris Eagle & Tim Vidas 10 | Implementation-URL: www.idabook.com/collabreate/ 11 | -------------------------------------------------------------------------------- /server/java/collabreate/server/server_manifest.mf: -------------------------------------------------------------------------------- 1 | Main-Class: collabreate.server.CollabreateServer 2 | Class-Path: mysql-connector-java-5.1.13-bin.jar postgresql-9.0-801.jdbc4.jar 3 | Name: collabreate/server/CollabreateServer/ 4 | Specification-Title: CollabREate Server 5 | Specification-Version: 0.4.0 6 | Specification-Vendor: Chris Eagle & Tim Vidas. 7 | Implementation-Title: CollabREate Server 8 | Implementation-Version: Ida Qt 9 | Implementation-Vendor: Chris Eagle & Tim Vidas 10 | Implementation-URL: www.idabook.com/collabreate/ 11 | -------------------------------------------------------------------------------- /server/java/collabreate/server/launch_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #the CLASSPATH should already be setup in the jar file, if not 4 | #you can try something like: 5 | #CLASSPATH=mysql-connector-java-5.1.13-bin.jar:postgresql-9.0-801.jdbc4.jar 6 | #java -classpath $CLASSPATH -jar collabreate_server.jar $1 > /dev/null 2>&1 < /dev/null & 7 | 8 | #or even execute the class files directly: 9 | #java collabreate.server.CollabreateServer collabreate/server/example_server.json 10 | 11 | java -jar collabreate_server.jar server.json > /dev/null 2>&1 < /dev/null & 12 | 13 | -------------------------------------------------------------------------------- /json-c/random_seed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * random_seed.h 3 | * 4 | * Copyright (c) 2013 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | */ 11 | 12 | /** 13 | * @file 14 | * @brief Do not use, json-c internal, may be changed or removed at any time. 15 | */ 16 | #ifndef seed_h 17 | #define seed_h 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | extern int json_c_get_random_seed(); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /json-c/strerror_override.h: -------------------------------------------------------------------------------- 1 | #ifndef _json_strerror_override_h_ 2 | #define _json_strerror_override_h_ 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | #include "config.h" 10 | #include 11 | 12 | #include "json_object.h" /* for JSON_EXPORT */ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include 19 | 20 | JSON_EXPORT char *_json_c_strerror(int errno_in); 21 | 22 | #ifndef STRERROR_OVERRIDE_IMPL 23 | #define strerror _json_c_strerror 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* _json_strerror_override_h_ */ 31 | -------------------------------------------------------------------------------- /json-c/math_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __math_compat_h 2 | #define __math_compat_h 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | /* Define isnan, isinf, infinity and nan on Windows/MSVC */ 10 | 11 | #ifndef HAVE_DECL_ISNAN 12 | # ifdef HAVE_DECL__ISNAN 13 | #include 14 | #define isnan(x) _isnan(x) 15 | # endif 16 | #endif 17 | 18 | #ifndef HAVE_DECL_ISINF 19 | # ifdef HAVE_DECL__FINITE 20 | #include 21 | #define isinf(x) (!_finite(x)) 22 | # endif 23 | #endif 24 | 25 | #ifndef HAVE_DECL_INFINITY 26 | #include 27 | #define INFINITY (DBL_MAX + DBL_MAX) 28 | #define HAVE_DECL_INFINITY 29 | #endif 30 | 31 | #ifndef HAVE_DECL_NAN 32 | #define NAN (INFINITY - INFINITY) 33 | #define HAVE_DECL_NAN 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /json-c/bits.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @deprecated Use json_util.h instead. 4 | * 5 | * $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $ 6 | * 7 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 8 | * Michael Clark 9 | * 10 | * This library is free software; you can redistribute it and/or modify 11 | * it under the terms of the MIT license. See COPYING for details. 12 | * 13 | */ 14 | 15 | #ifndef _bits_h_ 16 | #define _bits_h_ 17 | 18 | /** 19 | * @deprecated 20 | */ 21 | #define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) 22 | /** 23 | * @deprecated 24 | */ 25 | #define error_ptr(error) ((void*)error) 26 | /** 27 | * @deprecated 28 | */ 29 | #define error_description(error) (json_tokener_get_error(error)) 30 | /** 31 | * @deprecated 32 | */ 33 | #define is_error(ptr) (ptr == NULL) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /server/c++/Makefile: -------------------------------------------------------------------------------- 1 | SERVER_OBJS=server.o proj_info.o utils.o db_mgr.o client.o cli_mgr.o basic_mgr.o clientset.o projectmap.o mgr_helper.o io.o 2 | MGR_OBJS=server_mgr.o proj_info.o utils.o 3 | 4 | CC=g++ 5 | LD=g++ 6 | 7 | CFLAGS = -g 8 | CPPFLAGS = 9 | 10 | #Print error messages 11 | CFLAGS += -DDEBUG -Wall 12 | #NDEBUG=-D DEBUG 13 | 14 | #need the following when using threads 15 | EXTRALIBS=-lpthread -lpq -lcrypto -ljson-c 16 | 17 | LIBDIR=-L/usr/local/lib 18 | 19 | INC=-I/usr/include/postgresql -I/usr/local/include 20 | 21 | #use the following to strip your binary 22 | #LDFLAGS=-s 23 | 24 | all: collab collab_mgr 25 | 26 | collab: $(SERVER_OBJS) 27 | $(LD) $(LDFLAGS) -o $@ $(SERVER_OBJS) $(LIBDIR) $(EXTRALIBS) 28 | 29 | collab_mgr: $(MGR_OBJS) 30 | $(LD) $(LDFLAGS) -o $@ $(MGR_OBJS) $(LIBDIR) $(EXTRALIBS) 31 | 32 | %.o: %.cpp 33 | $(CC) -c $(CFLAGS) $(INC) $< -o $@ 34 | 35 | clean: 36 | -@rm *.o 37 | -------------------------------------------------------------------------------- /json-c/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: json.h,v 1.6 2006/01/26 02:16:28 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * Copyright (c) 2009 Hewlett-Packard Development Company, L.P. 7 | * 8 | * This library is free software; you can redistribute it and/or modify 9 | * it under the terms of the MIT license. See COPYING for details. 10 | * 11 | */ 12 | 13 | /** 14 | * @file 15 | * @brief A convenience header that may be included instead of other individual ones. 16 | */ 17 | #ifndef _json_h_ 18 | #define _json_h_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "debug.h" 25 | #include "linkhash.h" 26 | #include "arraylist.h" 27 | #include "json_util.h" 28 | #include "json_object.h" 29 | #include "json_pointer.h" 30 | #include "json_tokener.h" 31 | #include "json_object_iterator.h" 32 | #include "json_c_version.h" 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /json-c/snprintf_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __snprintf_compat_h 2 | #define __snprintf_compat_h 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | /* 10 | * Microsoft's _vsnprintf and _snprint don't always terminate 11 | * the string, so use wrappers that ensure that. 12 | */ 13 | 14 | #include 15 | 16 | #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) 17 | static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap) 18 | { 19 | int ret; 20 | ret = _vsnprintf(str, size, format, ap); 21 | str[size - 1] = '\0'; 22 | return ret; 23 | } 24 | #define vsnprintf json_c_vsnprintf 25 | 26 | static int json_c_snprintf(char *str, size_t size, const char *format, ...) 27 | { 28 | va_list ap; 29 | int ret; 30 | va_start(ap, format); 31 | ret = json_c_vsnprintf(str, size, format, ap); 32 | va_end(ap); 33 | return ret; 34 | } 35 | #define snprintf json_c_snprintf 36 | 37 | #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ 38 | # error Need vsnprintf! 39 | #endif /* !HAVE_SNPRINTF && defined(WIN32) */ 40 | 41 | #endif /* __snprintf_compat_h */ 42 | -------------------------------------------------------------------------------- /server/java/collabreate/server/my_server.conf: -------------------------------------------------------------------------------- 1 | # Sample config file for collabREate server 2 | 3 | # note, that trailing spaces should be ommitted 4 | 5 | # This file needs to be creatable/writable by the server user 6 | LogFile /var/log/collab 7 | 8 | #higher numbers result in loging more events 9 | LogVerbosity 44 10 | 11 | SERVER_PORT 5042 12 | 13 | SERVER_MODE database 14 | #SERVER_MODE basic 15 | 16 | JDBC_DRIVER com.mysql.jdbc.Driver 17 | JDBC_NAME mysql 18 | 19 | #JDBC_DRIVER org.postgresql.Driver 20 | #JDBC_NAME postgresql 21 | 22 | #Specifying JDBC_URL overrides JDBC_NAME, DB_HOST, DB_NAME, and USE_SSL 23 | #JDBC_URL jdbc:postgresql:///collabDB 24 | 25 | DB_HOST 127.0.0.1 26 | DB_NAME collabDB 27 | #USE_SSL yes 28 | USE_SSL no 29 | DB_USER collab 30 | DB_PASS collabpass 31 | 32 | ### these are used by the ServerManager 33 | # port for server to listen, client to connect 34 | MANAGE_PORT 5043 35 | # host for client to connect to 36 | #MANAGE_HOST icebox.uc.nps.edu 37 | MANAGE_HOST localhost 38 | #if MANAGE_LOCAL is non-zero the management port only accepts connection from localhost 39 | MANAGE_LOCAL 1 40 | 41 | -------------------------------------------------------------------------------- /server/java/collabreate/server/collabctl.7: -------------------------------------------------------------------------------- 1 | .TH collabctl 7 "Aug 16\, 2008" "CollabREate 0.1.0" "CollabREate control script" 2 | .SH NAME 3 | collabctl - crude control over the collabreate server (java) 4 | .SH SYNOPSIS 5 | .B collabctl [ 6 | .I options 7 | ] 8 | .SH DESCRIPTION 9 | .I collabctl 10 | is a control script for the java collabreate server component. It is recommended that you 11 | do not use this script directly, but use the init.d service control which uses this script. 12 | .PP 13 | .SH OPTIONS 14 | Options are given as command line arguements. 15 | .PP 16 | .TP 18 17 | .B start 18 | attempts to start the server 19 | .TP 20 | .B stop 21 | attempts to nicely stop the server 22 | .TP 23 | .B kill 24 | attempts to kill the server (and not other java processes) 25 | .SH RESOURCES 26 | collabREate documentation and updates are available at 27 | http://www.idabook.com/collabreate/ 28 | .PP 29 | .SH AUTHOR 30 | Man page written by Tim Vidas. 31 | 32 | CollabREate is written and maintainted by Chris Eagle and Tim Vidas. 33 | .SH BUGS 34 | None that we know of. 35 | .SH VERSION 36 | CollabREate 0.1.0 37 | .SH SEE ALSO 38 | java(n), collabreate_server(7), collabreate_manager(7) 39 | 40 | -------------------------------------------------------------------------------- /json-c/vasprintf_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __vasprintf_compat_h 2 | #define __vasprintf_compat_h 3 | 4 | /** 5 | * @file 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. 7 | */ 8 | 9 | #include "snprintf_compat.h" 10 | 11 | #if !defined(HAVE_VASPRINTF) 12 | /* CAW: compliant version of vasprintf */ 13 | static int vasprintf(char **buf, const char *fmt, va_list ap) 14 | { 15 | #ifndef WIN32 16 | static char _T_emptybuffer = '\0'; 17 | #endif /* !defined(WIN32) */ 18 | int chars; 19 | char *b; 20 | 21 | if(!buf) { return -1; } 22 | 23 | #ifdef WIN32 24 | chars = _vscprintf(fmt, ap)+1; 25 | #else /* !defined(WIN32) */ 26 | /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite 27 | our buffer like on some 64bit sun systems.... but hey, its time to move on */ 28 | chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1; 29 | if(chars < 0) { chars *= -1; } /* CAW: old glibc versions have this problem */ 30 | #endif /* defined(WIN32) */ 31 | 32 | b = (char*)malloc(sizeof(char)*chars); 33 | if(!b) { return -1; } 34 | 35 | if((chars = vsprintf(b, fmt, ap)) < 0) 36 | { 37 | free(b); 38 | } else { 39 | *buf = b; 40 | } 41 | 42 | return chars; 43 | } 44 | #endif /* !HAVE_VASPRINTF */ 45 | 46 | #endif /* __vasprintf_compat_h */ 47 | -------------------------------------------------------------------------------- /idanet.h: -------------------------------------------------------------------------------- 1 | /* 2 | Asynchronous IDA communications handler 3 | Copyright (C) 2018 Chris Eagle 4 | 5 | This program is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by the Free 7 | Software Foundation; either version 2 of the License, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, but WITHOUT 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | more details. 14 | 15 | You should have received a copy of the GNU General Public License along with 16 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 17 | Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | */ 20 | 21 | #ifndef __IDACONNECTOR_H__ 22 | #define __IDACONNECTOR_H__ 23 | 24 | #include 25 | 26 | typedef bool (*Dispatcher)(json_object *obj); 27 | 28 | #ifndef __NT__ 29 | #define _SOCKET int 30 | #define closesocket close 31 | #else 32 | #define _SOCKET unsigned int 33 | #endif 34 | 35 | bool connect_to(const char *host, short port, Dispatcher d); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /json-c/json_c_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012,2017 Eric Haszlakiewicz 3 | * 4 | * This library is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See COPYING for details. 6 | */ 7 | 8 | /** 9 | * @file 10 | * @brief Methods for retrieving the json-c version. 11 | */ 12 | #ifndef _json_c_version_h_ 13 | #define _json_c_version_h_ 14 | 15 | #define JSON_C_MAJOR_VERSION 0 16 | #define JSON_C_MINOR_VERSION 13 17 | #define JSON_C_MICRO_VERSION 99 18 | #define JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | \ 19 | (JSON_C_MINOR_VERSION << 8) | \ 20 | JSON_C_MICRO_VERSION) 21 | #define JSON_C_VERSION "0.13.99" 22 | 23 | /** 24 | * @see JSON_C_VERSION 25 | * @return the version of the json-c library as a string 26 | */ 27 | const char *json_c_version(void); /* Returns JSON_C_VERSION */ 28 | 29 | /** 30 | * The json-c version encoded into an int, with the low order 8 bits 31 | * being the micro version, the next higher 8 bits being the minor version 32 | * and the next higher 8 bits being the major version. 33 | * For example, 7.12.99 would be 0x00070B63. 34 | * 35 | * @see JSON_C_VERSION_NUM 36 | * @return the version of the json-c library as an int 37 | */ 38 | int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */ 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /server/server.json: -------------------------------------------------------------------------------- 1 | { 2 | "#title" : "# Sample config file for collabREate server", 3 | 4 | "#RUN_AS" : "collab", 5 | 6 | "#log_file" : "# This file needs to be creatable/writable by the server user", 7 | "LOG_FILE" : "/var/log/collab", 8 | 9 | "#log_verbosity" : "#higher numbers result in loging more events", 10 | "LOG_VERBOSITY" : 4, 11 | 12 | "PING_TIMEOUT" : 300, 13 | 14 | "SERVER_PORT" : 5042, 15 | 16 | "SERVER_MODE" : "database", 17 | "#SERVER_MODE" : "datbase, basic, or none", 18 | 19 | "JDBC_DRIVER" : "org.postgresql.Driver", 20 | "JDBC_NAME" : "postgresql", 21 | 22 | "#JDBC_DRIVER" : "com.mysql.jdbc.Driver", 23 | "#JDBC_NAME" : "mysql", 24 | 25 | "#jdbc_url" : "#Specifying JDBC_URL overrides JDBC_NAME, DB_HOST, DB_NAME, and USE_SSL", 26 | "#JDBC_URL" : "jdbc:postgresql://127.0.0.1/collabDB", 27 | 28 | "DB_HOST" : "127.0.0.1", 29 | "DB_NAME" : "collabDB", 30 | "USE_SSL" : "no", 31 | "DB_USER" : "collab", 32 | "DB_PASS" : "collabpass", 33 | 34 | "#server_manager" : "### these are used by the ServerManager ###", 35 | 36 | "#manage_port" : "# port for server to listen, client to connect", 37 | "MANAGE_PORT" : 5043, 38 | 39 | "#manage_host" : "# host for client to connect to", 40 | "MANAGE_HOST" : "localhost", 41 | 42 | "#manage_local" : "#if MANAGE_LOCAL is true the management port only accepts connections from localhost", 43 | "MANAGE_LOCAL" : true 44 | } 45 | -------------------------------------------------------------------------------- /collabreate_ui.h: -------------------------------------------------------------------------------- 1 | /* 2 | Collabreate GUI and communications layer 3 | Copyright (C) 2018 Chris Eagle 4 | 5 | This program is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by the Free 7 | Software Foundation; either version 2 of the License, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, but WITHOUT 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | more details. 14 | 15 | You should have received a copy of the GNU General Public License along with 16 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 17 | Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __COLLABREATE_GUI_H__ 21 | #define __COLLABREATE_GUI_H__ 22 | 23 | #include 24 | 25 | #include "idanet.h" 26 | 27 | int do_choose_command(); 28 | bool do_project_select(json_object *json); 29 | bool do_connect(Dispatcher d); 30 | int do_auth(unsigned char *challenge, int challenge_len); 31 | void do_set_req_perms(void); 32 | void do_set_proj_perms(void); 33 | bool do_auth(void); 34 | 35 | void createCollabStatus(); 36 | 37 | //void showOptionsDlg(HWND parent, Options *in, Options *out, Options *mask, char * title); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /server/c++/clientset.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate clientset.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __CLIENT_SET_H 22 | #define __CLIENT_SET_H 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class Client; 34 | 35 | using namespace std; 36 | 37 | typedef bool (*cb)(Client *c, void *user); 38 | 39 | class ClientSet { 40 | private: 41 | set clients; 42 | pthread_mutex_t mutex; 43 | 44 | public: 45 | ClientSet(); 46 | ~ClientSet(); 47 | 48 | void add(Client *c); 49 | void remove(Client *c); 50 | void loop(cb func, void *user); 51 | int size(); 52 | 53 | }; 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /json-c/json_object_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: json_object_private.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | */ 11 | 12 | /** 13 | * @file 14 | * @brief Do not use, json-c internal, may be changed or removed at any time. 15 | */ 16 | #ifndef _json_object_private_h_ 17 | #define _json_object_private_h_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define LEN_DIRECT_STRING_DATA 32 /**< how many bytes are directly stored in json_object for strings? */ 24 | 25 | typedef void (json_object_private_delete_fn)(struct json_object *o); 26 | 27 | struct json_object 28 | { 29 | enum json_type o_type; 30 | json_object_private_delete_fn *_delete; 31 | json_object_to_json_string_fn *_to_json_string; 32 | uint_fast32_t _ref_count; 33 | struct printbuf *_pb; 34 | union data { 35 | json_bool c_boolean; 36 | double c_double; 37 | int64_t c_int64; 38 | struct lh_table *c_object; 39 | struct array_list *c_array; 40 | struct { 41 | union { 42 | /* optimize: if we have small strings, we can store them 43 | * directly. This saves considerable CPU cycles AND memory. 44 | */ 45 | char *ptr; 46 | char data[LEN_DIRECT_STRING_DATA]; 47 | } str; 48 | int len; 49 | } c_string; 50 | } o; 51 | json_object_delete_fn *_user_delete; 52 | void *_userdata; 53 | }; 54 | 55 | void _json_c_set_last_err(const char *err_fmt, ...); 56 | 57 | extern const char *json_number_chars; 58 | extern const char *json_hex_chars; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /json-c/arraylist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: arraylist.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | */ 11 | 12 | /** 13 | * @file 14 | * @brief Internal methods for working with json_type_array objects. 15 | * Although this is exposed by the json_object_get_array() method, 16 | * it is not recommended for direct use. 17 | */ 18 | #ifndef _arraylist_h_ 19 | #define _arraylist_h_ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define ARRAY_LIST_DEFAULT_SIZE 32 26 | 27 | typedef void (array_list_free_fn) (void *data); 28 | 29 | struct array_list 30 | { 31 | void **array; 32 | size_t length; 33 | size_t size; 34 | array_list_free_fn *free_fn; 35 | }; 36 | typedef struct array_list array_list; 37 | 38 | extern struct array_list* 39 | array_list_new(array_list_free_fn *free_fn); 40 | 41 | extern void 42 | array_list_free(struct array_list *al); 43 | 44 | extern void* 45 | array_list_get_idx(struct array_list *al, size_t i); 46 | 47 | extern int 48 | array_list_put_idx(struct array_list *al, size_t i, void *data); 49 | 50 | extern int 51 | array_list_add(struct array_list *al, void *data); 52 | 53 | extern size_t 54 | array_list_length(struct array_list *al); 55 | 56 | extern void 57 | array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *)); 58 | 59 | extern void* array_list_bsearch(const void **key, 60 | struct array_list *arr, 61 | int (*sort_fn)(const void *, const void *)); 62 | 63 | extern int 64 | array_list_del_idx(struct array_list *arr, size_t idx, size_t count); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /vs13/collabreate.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "collabreate", "collabreate.vcxproj", "{E99929AE-83BD-4986-935A-B4D1BEF486D2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | Release64|Win32 = Release64|Win32 15 | Release64|x64 = Release64|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|Win32.Build.0 = Debug|Win32 20 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|x64.ActiveCfg = Debug|x64 21 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|x64.Build.0 = Debug|x64 22 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|Win32.ActiveCfg = Release|Win32 23 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|Win32.Build.0 = Release|Win32 24 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|x64.ActiveCfg = Release|x64 25 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|x64.Build.0 = Release|x64 26 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|Win32.ActiveCfg = Release64|Win32 27 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|Win32.Build.0 = Release64|Win32 28 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|x64.ActiveCfg = Release64|x64 29 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|x64.Build.0 = Release64|x64 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /vs17/collabreate.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "collabreate", "collabreate.vcxproj", "{E99929AE-83BD-4986-935A-B4D1BEF486D2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | Release64|Win32 = Release64|Win32 15 | Release64|x64 = Release64|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|Win32.Build.0 = Debug|Win32 20 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|x64.ActiveCfg = Debug|x64 21 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Debug|x64.Build.0 = Debug|x64 22 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|Win32.ActiveCfg = Release|Win32 23 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|Win32.Build.0 = Release|Win32 24 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|x64.ActiveCfg = Release|x64 25 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release|x64.Build.0 = Release|x64 26 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|Win32.ActiveCfg = Release64|Win32 27 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|Win32.Build.0 = Release64|Win32 28 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|x64.ActiveCfg = Release64|x64 29 | {E99929AE-83BD-4986-935A-B4D1BEF486D2}.Release64|x64.Build.0 = Release64|x64 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /server/java/collabreate/server/ProjectInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate ProjectInfo 3 | Copyright (C) 2008 Tim Vidas 4 | Copyright (C) 2008 Chris Eagle 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | package collabreate.server; 22 | 23 | /** 24 | * ProjectInfo is a helper classe to represent information pertitent 25 | * to a single project 26 | * @author Tim Vidas 27 | * @author Chris Eagle 28 | * @version 0.2.0, January 2017 29 | */ 30 | public class ProjectInfo { 31 | public int lpid; 32 | public String desc; 33 | public int connected; 34 | public int parent; 35 | public String pdesc; 36 | public long snapupdateid; 37 | public long pub; 38 | public long sub; 39 | public String owner; 40 | public String hash; 41 | public String gpid; 42 | public int proto; 43 | 44 | public ProjectInfo(int localpid, String description, int currentlyconnected) { 45 | lpid = localpid; 46 | desc = description; 47 | connected = currentlyconnected; 48 | } 49 | 50 | public ProjectInfo(int localpid, String description) { 51 | this(localpid, description, 0); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /json-c/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * Copyright (c) 2009 Hewlett-Packard Development Company, L.P. 7 | * 8 | * This library is free software; you can redistribute it and/or modify 9 | * it under the terms of the MIT license. See COPYING for details. 10 | * 11 | */ 12 | 13 | /** 14 | * @file 15 | * @brief Do not use, json-c internal, may be changed or removed at any time. 16 | */ 17 | #ifndef _DEBUG_H_ 18 | #define _DEBUG_H_ 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | extern void mc_set_debug(int debug); 27 | extern int mc_get_debug(void); 28 | 29 | extern void mc_set_syslog(int syslog); 30 | 31 | extern void mc_debug(const char *msg, ...); 32 | extern void mc_error(const char *msg, ...); 33 | extern void mc_info(const char *msg, ...); 34 | 35 | #ifndef __STRING 36 | #define __STRING(x) #x 37 | #endif 38 | 39 | #ifndef PARSER_BROKEN_FIXED 40 | 41 | #define JASSERT(cond) do {} while(0) 42 | 43 | #else 44 | 45 | #define JASSERT(cond) do { \ 46 | if (!(cond)) { \ 47 | mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \ 48 | *(int *)0 = 1;\ 49 | abort(); \ 50 | }\ 51 | } while(0) 52 | 53 | #endif 54 | 55 | #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__) 56 | 57 | #ifdef MC_MAINTAINER_MODE 58 | #define MC_SET_DEBUG(x) mc_set_debug(x) 59 | #define MC_GET_DEBUG() mc_get_debug() 60 | #define MC_SET_SYSLOG(x) mc_set_syslog(x) 61 | #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__) 62 | #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__) 63 | #else 64 | #define MC_SET_DEBUG(x) if (0) mc_set_debug(x) 65 | #define MC_GET_DEBUG() (0) 66 | #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x) 67 | #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__) 68 | #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__) 69 | #endif 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /vs13/collabreate.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 11 | 12 | 13 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 14 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | -------------------------------------------------------------------------------- /vs17/collabreate.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 11 | 12 | 13 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 14 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | -------------------------------------------------------------------------------- /server/c++/projectmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate projectmap.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __PROJECT_MAP_H 22 | #define __PROJECT_MAP_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class ClientSet; 33 | class Client; 34 | 35 | using namespace std; 36 | 37 | //project callback function 38 | typedef bool (*pcb)(ClientSet *c, void *user); 39 | //client callback function 40 | typedef bool (*ccb)(Client *c, void *user); 41 | 42 | class ProjectMap { 43 | private: 44 | map projects; 45 | pthread_mutex_t mutex; 46 | 47 | ClientSet *getPriv(uint32_t key); 48 | 49 | public: 50 | ProjectMap(); 51 | ~ProjectMap(); 52 | 53 | void put(uint32_t key, ClientSet *val); 54 | void addClient(uint32_t key, Client *c); 55 | void addClient(Client *c); 56 | void removeClient(Client *c); 57 | ClientSet *get(uint32_t key); 58 | int numClients(uint32_t key); 59 | //loop across all projects 60 | void loop(pcb func, void *user); 61 | //loop across all clients in a single project 62 | void loopProject(uint32_t key, ccb func, void *user); 63 | //loop across all clients in all projects 64 | void loopClients(ccb func, void *user); 65 | 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /server/c++/clientset.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate clientset.cpp 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include "client.h" 22 | #include "clientset.h" 23 | 24 | ClientSet::ClientSet() { 25 | pthread_mutexattr_t attr; 26 | pthread_mutexattr_init(&attr); 27 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 28 | pthread_mutex_init(&mutex, &attr); 29 | pthread_mutexattr_destroy(&attr); 30 | } 31 | 32 | ClientSet::~ClientSet() { 33 | pthread_mutex_destroy(&mutex); 34 | } 35 | 36 | //add a new client 37 | void ClientSet::add(Client *c) { 38 | pthread_mutex_lock(&mutex); 39 | clients.insert(c); 40 | pthread_mutex_unlock(&mutex); 41 | } 42 | 43 | //remove a client 44 | void ClientSet::remove(Client *c) { 45 | pthread_mutex_lock(&mutex); 46 | clients.erase(c); 47 | pthread_mutex_unlock(&mutex); 48 | } 49 | 50 | //iterate over all clients in the set 51 | void ClientSet::loop(cb func, void *user) { 52 | pthread_mutex_lock(&mutex); 53 | for (set::iterator i = clients.begin(); i != clients.end(); i++) { 54 | Client *c = *i; 55 | if (!(*func)(c, user)) { 56 | break; 57 | } 58 | } 59 | pthread_mutex_unlock(&mutex); 60 | } 61 | 62 | //return the size of the client set 63 | int ClientSet::size() { 64 | pthread_mutex_lock(&mutex); 65 | int res = clients.size(); 66 | pthread_mutex_unlock(&mutex); 67 | return res; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /server/c++/proj_info.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate proj_info.cpp 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include 22 | #include "proj_info.h" 23 | 24 | sem_t uidMutex; 25 | 26 | Project::Project(uint32_t localpid, const string &description, uint32_t currentlyconnected) { 27 | lpid = localpid; 28 | desc = description; 29 | connected = currentlyconnected; 30 | parent = 0; 31 | pdesc = ""; 32 | snapupdateid = 0; 33 | pub = sub = 0; 34 | proto = 0; 35 | hash = ""; 36 | gpid = ""; 37 | } 38 | 39 | Project::Project(const Project &p) { 40 | *this = p; 41 | } 42 | 43 | BasicProject::BasicProject(uint32_t localpid, const string &description, uint32_t currentlyconnected, uint64_t init_uid) : 44 | Project(localpid, description, currentlyconnected) { 45 | updateid = init_uid; 46 | sem_init(&uidMutex, 0, 1); 47 | } 48 | 49 | BasicProject::BasicProject(const BasicProject &bp) { 50 | *this = bp; 51 | } 52 | 53 | BasicProject::~BasicProject() { 54 | for (vector::iterator i = updates.begin(); i != updates.end(); i++) { 55 | free(*i); 56 | } 57 | } 58 | 59 | uint64_t BasicProject::next_uid() { 60 | uint64_t result; 61 | sem_wait(&uidMutex); 62 | result = ++updateid; 63 | sem_post(&uidMutex); 64 | return result; 65 | } 66 | 67 | void BasicProject::append_update(const char *update) { 68 | updates.push_back(strdup(update)); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /server/java/collabreate/server/build_jar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #take care of people having different versions of the JDBC connectors 4 | #the jar manifest needs the correct file names 5 | SQLJAR=`ls *mysql*.jar 2>/dev/null` 6 | POSTGRESJAR=`ls *postgres*.jar 2>/dev/null` 7 | MYCP="$SQLJAR $POSTGRESJAR gson-2.8.0.jar" 8 | 9 | echo "Using these JDBC connectors:$MYCP" 10 | 11 | #create the manifest files 12 | echo "Main-Class: collabreate.server.CollabreateServer" > server_manifest.mf 13 | echo "Class-Path: $MYCP" >> server_manifest.mf 14 | echo "Name: collabreate/server/CollabreateServer/" >> server_manifest.mf 15 | echo "Specification-Title: CollabREate Server" >> server_manifest.mf 16 | echo "Specification-Version: 0.4.0" >> server_manifest.mf 17 | echo "Specification-Vendor: Chris Eagle & Tim Vidas." >> server_manifest.mf 18 | echo "Implementation-Title: CollabREate Server" >> server_manifest.mf 19 | echo "Implementation-Version: Ida Qt" >> server_manifest.mf 20 | echo "Implementation-Vendor: Chris Eagle & Tim Vidas" >> server_manifest.mf 21 | echo "Implementation-URL: www.idabook.com/collabreate/" >> server_manifest.mf 22 | 23 | echo "Main-Class: collabreate.server.ServerManager" > manager_manifest.mf 24 | echo "Class-Path: $MYCP" >> manager_manifest.mf 25 | echo "Name: collabreate/server/CollabreateServer/" >> manager_manifest.mf 26 | echo "Specification-Title: CollabREate Server" >> manager_manifest.mf 27 | echo "Specification-Version: 0.4.0" >> manager_manifest.mf 28 | echo "Specification-Vendor: Chris Eagle & Tim Vidas." >> manager_manifest.mf 29 | echo "Implementation-Title: CollabREate Server" >> manager_manifest.mf 30 | echo "Implementation-Version: Ida Qt" >> manager_manifest.mf 31 | echo "Implementation-Vendor: Chris Eagle & Tim Vidas" >> manager_manifest.mf 32 | echo "Implementation-URL: www.idabook.com/collabreate/" >> manager_manifest.mf 33 | 34 | #build the jar files 35 | cd ../.. 36 | javac -cp gson-2.8.0.jar collabreate/server/*.java 37 | 38 | jar cfm collabreate_server.jar collabreate/server/server_manifest.mf gson-2.8.0.jar collabreate/server/*.class 39 | mv -f collabreate_server.jar collabreate/server 40 | 41 | jar cfm collabreate_manager.jar collabreate/server/manager_manifest.mf gson-2.8.0.jar collabreate/server/*.class 42 | mv -f collabreate_manager.jar collabreate/server 43 | 44 | cd collabreate/server 45 | -------------------------------------------------------------------------------- /server/c++/proj_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate proj_info.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __PROJ_INFO_H 22 | #define __PROJ_INFO_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | 31 | /* 32 | * A class that wraps project metadata 33 | */ 34 | class Project { 35 | public: 36 | uint32_t lpid; 37 | string desc; 38 | uint32_t connected; 39 | int32_t parent; 40 | string pdesc; 41 | uint64_t snapupdateid; 42 | uint64_t pub; 43 | uint64_t sub; 44 | string owner; 45 | uint32_t proto; 46 | string hash; 47 | string gpid; 48 | 49 | Project(uint32_t localpid, const string &description, uint32_t currentlyconnected = 0); 50 | Project(const Project &pi); 51 | 52 | protected: 53 | Project() {}; 54 | }; 55 | 56 | /* 57 | * Subclass that provides for basic (as opposed to database backed) storage of received updates 58 | */ 59 | 60 | class BasicProject : public Project { 61 | public: 62 | BasicProject(uint32_t localpid, const string &description, uint32_t currentlyconnected = 0, uint64_t init_uid = 0); 63 | BasicProject(const BasicProject &pi); 64 | ~BasicProject(); 65 | 66 | uint64_t next_uid(); 67 | uint64_t curr_uid(); 68 | 69 | void append_update(const char *update); 70 | const vector &get_updates() {return updates;}; 71 | 72 | private: 73 | sem_t uidMutex; 74 | uint64_t updateid; 75 | vector updates; 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /server/java/collabreate/server/HmacMD5.java: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate HmacMD5 3 | Copyright (C) 2008 Chris Eagle 4 | Copyright (C) 2008 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | package collabreate.server; 22 | 23 | import java.security.*; 24 | 25 | /** 26 | * HmacMD5 27 | * This class is responsible for computing an HmacMD5 value 28 | * for use in the challenge and response authentication portion 29 | * of a collabreate server connection, see RFC 2104 30 | * @author Tim Vidas 31 | * @author Chris Eagle 32 | * @version 0.1.0, August 2008 33 | */ 34 | 35 | public class HmacMD5 { 36 | /** 37 | * hmac calculates an HmacMD5 value 38 | * @param msg a byte array to hash 39 | * @param key a byte array to use as the hmac key 40 | * @return the hmacMD5 41 | */ 42 | protected static byte[] hmac(byte[] msg, byte[] key) { 43 | MessageDigest md5 = null; 44 | try { 45 | md5 = MessageDigest.getInstance("MD5"); 46 | } catch (Exception ex) { 47 | } 48 | if (key.length > 64) { 49 | md5.reset(); 50 | key = md5.digest(key); 51 | } 52 | byte ipad[] = new byte[64]; 53 | System.arraycopy(key, 0, ipad, 0, key.length); 54 | byte opad[] = ipad.clone(); 55 | 56 | /* XOR key with ipad and opad values */ 57 | for (int i = 0; i < ipad.length; i++) { 58 | ipad[i] ^= (byte)0x36; 59 | opad[i] ^= (byte)0x5c; 60 | } 61 | 62 | // perform inner MD5 63 | md5.reset(); 64 | md5.update(ipad); 65 | byte digest[] = md5.digest(msg); 66 | 67 | // perform outer MD5 68 | md5.reset(); 69 | md5.update(opad); 70 | return md5.digest(digest); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | * 01/13/18 2 | Migrate to json based protocol. Old protocol and database form no longer supported. 3 | Supporting IDA versions 6.5-7.0 4 | Binaries now land in bin directory 5 | 6 | * 01/02/17 7 | Conversion to protocol version 4, a JSON based messaging protocol 8 | Only the C++ server has been updated at this point 9 | Attempt to use only native IDA api functions for user interface 10 | Eliminate QT specific code to make building easier 11 | 12 | * 05/25/14 13 | Added primitive messaging capability in CollabREate window. Message history is 14 | cached in the IDB and restored with each session. 15 | Added primitive support for working offline. If IDB has been previously joined 16 | to a project, then all changes in subsequent sessions will be cached locally 17 | until reconnected to the project server. 18 | 19 | * 10/04/13 20 | Added support for repeatable comments in struct/enum per suggestion of Nico Bendlin 21 | Added support for additional offset reference types in COMMAND_OP_TYPE_CHANGED per 22 | contribution of Willem Jan Palenstijn 23 | Fixed handling of enum member comments and struct member comments 24 | 25 | * 10/01/13 26 | Incorporated patch contributions from Willem Jan Palenstijn 27 | 28 | * 08/24/12 29 | Removed dependency on QtNetwork. Reworked asynchronous networking 30 | for IDA versions 5.5 and later to make use of the IDA SDK execute_sync 31 | function. 32 | 33 | * 09/08/11 34 | Added support for ida64, released version 0.3.0 35 | 36 | * 10/20/10 37 | Added message handler for MSG_PROJECT_SNAPSHOT_REPLY 38 | 39 | * 10/12/10 40 | Completed port to Qt for Linux and OS X 41 | 42 | * 10/08/10 43 | Added initial Qt interface for Ida >= 6.0 44 | Added ubuntu-init.d-script server startup script contributed by William Bartell 45 | Added NO_OBSOLETE_FUNCTIONS macro into the project 46 | 47 | * 02/28/09 48 | Fixed buffer overflow problem pointed out by Jeremy Cooper 49 | 50 | * 08/27/08 51 | Added local tracking of enum names to allow renaming of enums to work. 52 | Added more tests to narrow down the exact type being referenced when 53 | an operand type is changed. Specifically enum and structure offsets. 54 | These changes will not fix enum and struct updates in existing project 55 | databases, however new enum and struct updates will be properly stored 56 | into those databases once you have upgraded you plugin. 57 | 58 | * 08/24/08 59 | Fix to allow proper publishing of name changes that take place in the 60 | .bss section 61 | 62 | * 08/16/08 63 | added permission handling for COMMAND_AREA_CMT_CHANGED 64 | 65 | * 08/15/08 66 | Initial release of version 1.0 67 | -------------------------------------------------------------------------------- /server/c++/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate io.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __COLLAB_IO_H 22 | #define __COLLAB_IO_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using std::string; 32 | using std::vector; 33 | 34 | struct sockaddr_in6; 35 | class NetworkIO; 36 | 37 | class IOException { 38 | public: 39 | IOException(const string &msg = ""); 40 | const string &getMessage(); 41 | private: 42 | string msg; 43 | }; 44 | 45 | class NetworkIO { 46 | public: 47 | NetworkIO() {this->fd = -1; did_ping = false;}; 48 | NetworkIO(int fd) {this->fd = fd; did_ping = false;}; 49 | ~NetworkIO() {close();}; 50 | 51 | bool writeJson(json_object *obj); 52 | ssize_t sendMsg(const char *buf, bool nullflag = 0); 53 | ssize_t sendAll(const void *buf, ssize_t len); 54 | ssize_t sendFormat(const char *format, ...); 55 | 56 | json_object *readJson(); 57 | int getPeerPort(); 58 | string getPeerAddr(); 59 | bool close(); 60 | protected: 61 | int fd; 62 | private: 63 | string json_buffer; 64 | bool did_ping; 65 | }; 66 | 67 | class NetworkService { 68 | public: 69 | virtual ~NetworkService(); 70 | virtual NetworkIO *accept() = 0; 71 | virtual bool close(); 72 | protected: 73 | vector fds; 74 | fd_set aset; 75 | int nfds; 76 | }; 77 | 78 | class Tcp6Service : public NetworkService { 79 | public: 80 | Tcp6Service(int port); 81 | Tcp6Service(const char *host, int port); 82 | virtual ~Tcp6Service(); 83 | NetworkIO *accept(); 84 | private: 85 | sockaddr_in6 *self; 86 | }; 87 | 88 | class Tcp6IO : public NetworkIO { 89 | public: 90 | Tcp6IO(int fd, sockaddr_in6 &peer); 91 | ~Tcp6IO(); 92 | 93 | private: 94 | sockaddr_in6 *peer; 95 | }; 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /server/java/collabreate/server/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | IDA Pro Collabreation/Synchronization Plugin 3 | Copyright (C) 2008 Chris Eagle 4 | Copyright (C) 2008 Tim Vidas 5 | 6 | 7 | This program is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by the Free 9 | Software Foundation; either version 2 of the License, or (at your option) 10 | any later version. 11 | 12 | This program is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 | more details. 16 | 17 | You should have received a copy of the GNU General Public License along with 18 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 19 | Place, Suite 330, Boston, MA 02111-1307 USA 20 | 21 | 22 | Depending on how you aquired CollabREate, you may have also recieved a compiled 23 | version of the postgres JDBC connector. If so, that software is bound by the 24 | following license: 25 | 26 | Copyright (c) 1997-2008, PostgreSQL Global Development Group 27 | All rights reserved. 28 | 29 | Redistribution and use in source and binary forms, with or without 30 | modification, are permitted provided that the following conditions are met: 31 | 32 | 1. Redistributions of source code must retain the above copyright notice, 33 | this list of conditions and the following disclaimer. 34 | 2. Redistributions in binary form must reproduce the above copyright notice, 35 | this list of conditions and the following disclaimer in the documentation 36 | and/or other materials provided with the distribution. 37 | 3. Neither the name of the PostgreSQL Global Development Group nor the names 38 | of its contributors may be used to endorse or promote products derived 39 | from this software without specific prior written permission. 40 | 41 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 42 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 45 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 46 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 47 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 51 | POSSIBILITY OF SUCH DAMAGE. 52 | 53 | 54 | Depending on how you aquired CollabREate, you may have also recieved a compiled 55 | version of the mysql JDBC connector. If so, that software is bound by the 56 | GPL 2.0 license, which is the same license CollabREate covered by and can be 57 | found in the accompanying GPL.txt file. 58 | 59 | -------------------------------------------------------------------------------- /server/java/collabreate/server/collabreate_server.7: -------------------------------------------------------------------------------- 1 | .TH collabreate_server 7 "Aug 16\, 2008" "CollabREate 0.1.0" "CollabREate Collaboration Server" 2 | .SH NAME 3 | collabreate_server - server intended to be used with the collabREate IDA Pro Plugin 4 | .SH SYNOPSIS 5 | .B java collabreate.server.CollabreateServer /path/to/server.conf 6 | .SH DESCRIPTION 7 | .I collabreate_server 8 | is the server component for the collabREate collaborative reverse engineering tool. 9 | One or more instances of IDA Pro can connect to the server using the collabREate plugin. 10 | Consult the 11 | .I collabreate_server 12 | README file or www.idabook.com/collabreate for more information 13 | .PP 14 | .SH OPTIONS 15 | Options are configured via the server.conf file, which can be shared with the manager 16 | .PP 17 | .TP 18 18 | .B LogFile 19 | Specifies the full path that the server will log to. Needs to be creatable/writable by service user. 20 | .TP 21 | .B LogVerbosity 22 | The port that the server will listen on. This port is required for collabREate clients to connect. (4) 23 | .TP 24 | .B SERVER_PORT 25 | defines the TCP port on which the collabreate server will accept connections from IDA plugins (5042) 26 | .TP 27 | .B SERVER_MODE 28 | Explicitly sets the collabreate server mode. It must be either 29 | .I basic 30 | or 31 | .I database. 32 | Note that if the server cannot start in database mode, it falls back to basic mode. (database) 33 | .TP 34 | .B JDBC_DRIVER 35 | defines the 'java name' of the JDBC driver. Only 36 | .I org.postgresql.Driver 37 | and 38 | .I con.mysql.jdbc.Driver 39 | are currently supported. (org.postgresql.Driver) 40 | .TP 41 | .B JDBC_URL 42 | this is a 'long style' JDBC url specifier. If you use this option other database configuration 43 | options (like DB_HOST, DB_NAME, DB_USER, etc) are ignored. (undefined) 44 | .TP 45 | .B DB_HOST 46 | the hostname or IP of the database server (127.0.0.1) 47 | .TP 48 | .B DB_NAME 49 | the name of the database (collabDB) 50 | .TP 51 | .B USE_SSL 52 | determins whether JDBC will attmpt so use SSL when connected to the database. Must be set to 53 | .I yes 54 | or 55 | .I no 56 | and both your JDBC driver AND your database must support SSL (many installs do not by default). (no) 57 | .TP 58 | .B DB_USER 59 | the username to use when connecting to the database (collab) 60 | .TP 61 | .B DB_PASS 62 | the password to use when connecting to the database (collabpass) 63 | .TP 64 | .B MANAGE_PORT 65 | defines the TCP port number that the server will listen on for management connections (5043) 66 | .TP 67 | .B MANAGE_HOST 68 | defines the host that ServerManager will connect to - so not really used by the server. (localhost) 69 | .TP 70 | .B MANAGE_LOCAL 71 | if this value is non-zero, the listening management socket on the server will only accept connections 72 | from localhost. (1) 73 | 74 | .SH RESOURCES 75 | collabREate documentation and updates are available at 76 | http://www.idabook.com/collabreate/ 77 | .PP 78 | .SH AUTHOR 79 | Man page written by Tim Vidas. 80 | 81 | CollabREate is written and maintainted by Chris Eagle and Tim Vidas. 82 | .SH BUGS 83 | None that we know of. 84 | .SH VERSION 85 | CollabREate 0.1.0 86 | .SH SEE ALSO 87 | java(n), collabreate_manager(7), collabctl(7) 88 | 89 | -------------------------------------------------------------------------------- /server/c++/db_mgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate db_mgr.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __DB_SUPPORT_H 22 | #define __DB_SUPPORT_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "cli_mgr.h" 30 | #include "client.h" 31 | #include "proj_info.h" 32 | 33 | using namespace std; 34 | 35 | class DatabaseConnectionManager : public ConnectionManager { 36 | public: 37 | DatabaseConnectionManager(json_object *conf); 38 | virtual ~DatabaseConnectionManager(); 39 | 40 | /** 41 | * doAuth authenticates a user 42 | * bacially this is standard CHAP with HMAC (md5) 43 | * @param nio The network connection to authenticate 44 | * @return the user id of an authenticated user, or failure code 45 | */ 46 | uint32_t doAuth(NetworkIO *nio); 47 | 48 | void importUpdate(const char *newowner, int pid, const char *cmd, json_object *obj); 49 | void post(Client *src, const char *cmd, json_object *obj); 50 | void sendLatestUpdates(Client *c, uint64_t lastUpdate); 51 | const Project *getProject(uint32_t pid); 52 | 53 | vector *getProjectList(const string &phash); 54 | vector *getAllProjects(); 55 | int joinProject(Client *c, uint32_t lpid); 56 | int snapProject(Client *c, uint64_t lastupdateid, const string &desc); 57 | int forkProject(Client *c, uint64_t lastupdateid, const string &desc); 58 | int forkProject(Client *c, uint64_t lastupdateid, const string &desc, uint64_t pub, uint64_t sub); 59 | void sendForkFollows(Client *originator, int oldlpid, uint64_t lastupdateid, const string &desc); 60 | int snapforkProject(Client *c, int spid, const string &desc, uint64_t pub, uint64_t sub); 61 | int importProject(const char *owner, const string &gpid, const string &hash, const string &desc, uint64_t pub, uint64_t sub); 62 | json_object *exportProject(uint32_t pid); 63 | int addProject(Client *c, const string &hash, const string &desc, uint64_t pub, uint64_t sub); 64 | void updateProjectPerms(Client *c, uint64_t pub, uint64_t sub); 65 | int gpid2lpid(const string &gpid); 66 | 67 | private: 68 | map pid_project_map; 69 | 70 | void init_queries(); 71 | 72 | sem_t pu_sem; 73 | sem_t ap_sem; 74 | sem_t aps_sem; 75 | sem_t apf_sem; 76 | sem_t fp_sem; 77 | sem_t fpbh_sem; 78 | sem_t fpbp_sem; 79 | sem_t fpbg_sem; 80 | sem_t gui_sem; 81 | sem_t glu_sem; 82 | sem_t cu_sem; 83 | sem_t ppu_sem; 84 | sem_t map_sem; 85 | 86 | PGconn *dbConn; 87 | }; 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /server/java/collabreate/server/collabreate_manager.7: -------------------------------------------------------------------------------- 1 | .TH collabreate_manager 7 "Aug 16\, 2008" "CollabREate 0.1.0" "CollabREate Collaboration Server" 2 | .SH NAME 3 | collabreate_manager - manager intended to be used with the collabREate server 4 | .SH SYNOPSIS 5 | .B java collabreate.server.ServerManager [ shutdown ] /path/to/server.conf 6 | .SH DESCRIPTION 7 | .I collabreate_manager 8 | is the manager component for the collabREate server. Once ServerManager can connect to a server 9 | instance at a time. By default, the server only listens for a ServerManager on localhost. 10 | Consult the 11 | .I collabreate_server 12 | README file or www.idabook.com/collabreate for more information 13 | .PP 14 | .SH OPTIONS 15 | Most options are configured via the server.conf file, which can be shared with the server 16 | .PP 17 | .TP 18 18 | .B shutdown 19 | When this option is passed on the command line, it causes the ServerManager to invoke the shutdown 20 | process on the server. This allows the server to perform actions prior to termination and is prefered 21 | over a 'kill' 22 | .B LogFile 23 | Specifies the full path that the server will log to. Needs to be creatable/writable by service user. 24 | .TP 25 | .B LogVerbosity 26 | The port that the server will listen on. This port is required for collabREate clients to connect. (4) 27 | .TP 28 | .B SERVER_PORT 29 | defines the TCP port on which the collabreate server will accept connections from IDA plugins (5042) 30 | not used by the manager 31 | .TP 32 | .B SERVER_MODE 33 | Explicitly sets the collabreate server mode. It must be either 34 | .I basic 35 | or 36 | .I database. 37 | Note that if the server cannot start in database mode, it falls back to basic mode. (database) 38 | .TP 39 | .B JDBC_DRIVER 40 | defines the 'java name' of the JDBC driver. Only 41 | .I org.postgresql.Driver 42 | and 43 | .I con.mysql.jdbc.Driver 44 | are currently supported. (org.postgresql.Driver) 45 | .TP 46 | .B JDBC_URL 47 | this is a 'long style' JDBC url specifier. If you use this option other database configuration 48 | options (like DB_HOST, DB_NAME, DB_USER, etc) are ignored. (undefined) 49 | .TP 50 | .B DB_HOST 51 | the hostname or IP of the database server (127.0.0.1) 52 | .TP 53 | .B DB_NAME 54 | the name of the database (collabDB) 55 | .TP 56 | .B USE_SSL 57 | determins whether JDBC will attmpt so use SSL when connected to the database. Must be set to 58 | .I yes 59 | or 60 | .I no 61 | and both your JDBC driver AND your database must support SSL (many installs do not by default). (no) 62 | .TP 63 | .B DB_USER 64 | the username to use when connecting to the database (collab) 65 | .TP 66 | .B DB_PASS 67 | the password to use when connecting to the database (collabpass) 68 | .TP 69 | .B MANAGE_PORT 70 | defines the TCP port number that the manager will use to connect to the server (5043) 71 | .TP 72 | .B MANAGE_HOST 73 | defines the host that ServerManager will connect to. (localhost) 74 | .TP 75 | .B MANAGE_LOCAL 76 | if this value is non-zero, the listening management socket on the server will only accept connections 77 | from localhost - not really used by the manager. (1) 78 | 79 | .SH RESOURCES 80 | collabREate documentation and updates are available at 81 | http://www.idabook.com/collabreate/ 82 | .PP 83 | .SH AUTHOR 84 | Man page written by Tim Vidas. 85 | 86 | CollabREate is written and maintainted by Chris Eagle and Tim Vidas. 87 | .SH BUGS 88 | None that we know of. 89 | .SH VERSION 90 | CollabREate 0.1.0 91 | .SH SEE ALSO 92 | java(n), collabreate_server(7), collabctl(7) 93 | 94 | -------------------------------------------------------------------------------- /json-c/json_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | */ 11 | 12 | /** 13 | * @file 14 | * @brief Miscllaneous utility functions and macros. 15 | */ 16 | #ifndef _json_util_h_ 17 | #define _json_util_h_ 18 | 19 | #include "json_object.h" 20 | 21 | #ifndef json_min 22 | #define json_min(a,b) ((a) < (b) ? (a) : (b)) 23 | #endif 24 | 25 | #ifndef json_max 26 | #define json_max(a,b) ((a) > (b) ? (a) : (b)) 27 | #endif 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define JSON_FILE_BUF_SIZE 4096 35 | 36 | /* utility functions */ 37 | /** 38 | * Read the full contents of the given file, then convert it to a 39 | * json_object using json_tokener_parse(). 40 | * 41 | * Returns -1 if something fails. See json_util_get_last_err() for details. 42 | */ 43 | extern struct json_object* json_object_from_file(const char *filename); 44 | 45 | /** 46 | * Create a JSON object from already opened file descriptor. 47 | * 48 | * This function can be helpful, when you opened the file already, 49 | * e.g. when you have a temp file. 50 | * Note, that the fd must be readable at the actual position, i.e. 51 | * use lseek(fd, 0, SEEK_SET) before. 52 | * 53 | * Returns -1 if something fails. See json_util_get_last_err() for details. 54 | */ 55 | extern struct json_object* json_object_from_fd(int fd); 56 | 57 | /** 58 | * Equivalent to: 59 | * json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN); 60 | * 61 | * Returns -1 if something fails. See json_util_get_last_err() for details. 62 | */ 63 | extern int json_object_to_file(const char *filename, struct json_object *obj); 64 | 65 | /** 66 | * Open and truncate the given file, creating it if necessary, then 67 | * convert the json_object to a string and write it to the file. 68 | * 69 | * Returns -1 if something fails. See json_util_get_last_err() for details. 70 | */ 71 | extern int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags); 72 | 73 | /** 74 | * Convert the json_object to a string and write it to the file descriptor. 75 | * Handles partial writes and will keep writing until done, or an error 76 | * occurs. 77 | * 78 | * @param fd an open, writable file descriptor to write to 79 | * @param obj the object to serializer and write 80 | * @param flags flags to pass to json_object_to_json_string_ext() 81 | * @return -1 if something fails. See json_util_get_last_err() for details. 82 | */ 83 | extern int json_object_to_fd(int fd, struct json_object *obj, int flags); 84 | 85 | /** 86 | * Return the last error from various json-c functions, including: 87 | * json_object_to_file{,_ext}, json_object_to_fd() or 88 | * json_object_from_{file,fd}, or NULL if there is none. 89 | */ 90 | const char *json_util_get_last_err(void); 91 | 92 | 93 | extern int json_parse_int64(const char *buf, int64_t *retval); 94 | extern int json_parse_double(const char *buf, double *retval); 95 | 96 | /** 97 | * Return a string describing the type of the object. 98 | * e.g. "int", or "object", etc... 99 | */ 100 | extern const char *json_type_to_name(enum json_type o_type); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /json-c/json_visit.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _json_c_json_visit_h_ 3 | #define _json_c_json_visit_h_ 4 | 5 | /** 6 | * @file 7 | * @brief Methods for walking a tree of objects. 8 | */ 9 | #include "json_object.h" 10 | 11 | typedef int (json_c_visit_userfunc)(json_object *jso, int flags, 12 | json_object *parent_jso, const char *jso_key, 13 | size_t *jso_index, void *userarg); 14 | 15 | /** 16 | * Visit each object in the JSON hierarchy starting at jso. 17 | * For each object, userfunc is called, passing the object and userarg. 18 | * If the object has a parent (i.e. anything other than jso itself) 19 | * its parent will be passed as parent_jso, and either jso_key or jso_index 20 | * will be set, depending on whether the parent is an object or an array. 21 | * 22 | * Nodes will be visited depth first, but containers (arrays and objects) 23 | * will be visited twice, the second time with JSON_C_VISIT_SECOND set in 24 | * flags. 25 | * 26 | * userfunc must return one of the defined return values, to indicate 27 | * whether and how to continue visiting nodes, or one of various ways to stop. 28 | * 29 | * Returns 0 if nodes were visited successfully, even if some were 30 | * intentionally skipped due to what userfunc returned. 31 | * Returns <0 if an error occurred during iteration, including if 32 | * userfunc returned JSON_C_VISIT_RETURN_ERROR. 33 | */ 34 | int json_c_visit(json_object *jso, int future_flags, 35 | json_c_visit_userfunc *userfunc, void *userarg); 36 | 37 | /** 38 | * Passed to json_c_visit_userfunc as one of the flags values to indicate 39 | * that this is the second time a container (array or object) is being 40 | * called, after all of it's members have been iterated over. 41 | */ 42 | #define JSON_C_VISIT_SECOND 0x02 43 | 44 | /** 45 | * This json_c_visit_userfunc return value indicates that iteration 46 | * should proceed normally. 47 | */ 48 | #define JSON_C_VISIT_RETURN_CONTINUE 0 49 | 50 | 51 | /** 52 | * This json_c_visit_userfunc return value indicates that iteration 53 | * over the members of the current object should be skipped. 54 | * If the current object isn't a container (array or object), this 55 | * is no different than JSON_C_VISIT_RETURN_CONTINUE. 56 | */ 57 | #define JSON_C_VISIT_RETURN_SKIP 7547 58 | 59 | /** 60 | * This json_c_visit_userfunc return value indicates that iteration 61 | * of the fields/elements of the containing object should stop 62 | * and continue "popped up" a level of the object hierarchy. 63 | * For example, returning this when handling arg will result in 64 | * arg3 and any other fields being skipped. The next call to userfunc 65 | * will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc 66 | * call on "bar". 67 | *
68 |  * {
69 |  *   "foo": {
70 |  *     "arg1": 1,
71 |  *     "arg2": 2,
72 |  *     "arg3": 3,
73 |  *     ...
74 |  *   },
75 |  *   "bar": {
76 |  *     ...
77 |  *   }
78 |  * }
79 |  * 
80 | */ 81 | #define JSON_C_VISIT_RETURN_POP 767 82 | 83 | /** 84 | * This json_c_visit_userfunc return value indicates that iteration 85 | * should stop immediately, and cause json_c_visit to return success. 86 | */ 87 | #define JSON_C_VISIT_RETURN_STOP 7867 88 | 89 | /** 90 | * This json_c_visit_userfunc return value indicates that iteration 91 | * should stop immediately, and cause json_c_visit to return an error. 92 | */ 93 | #define JSON_C_VISIT_RETURN_ERROR -1 94 | 95 | #endif /* _json_c_json_visit_h_ */ 96 | -------------------------------------------------------------------------------- /server/c++/mgr_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate mgr_helper.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __MANAGER_HELPER_H 22 | #define __MANAGER_HELPER_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "io.h" 29 | #include "utils.h" 30 | #include "client.h" 31 | 32 | using namespace std; 33 | 34 | class ConnectionManager; 35 | class ManagerHelper; 36 | 37 | typedef void (*MsgHandler)(json_object *obj, ManagerHelper *mh); 38 | 39 | /** 40 | * ManagerHelper 41 | * This class is intented to facilitate getting current status information to 42 | * the ServerManager class. 43 | * @author Tim Vidas 44 | * @author Chris Eagle 45 | * @version 0.4.0, August 2012 46 | */ 47 | 48 | class ManagerHelper { 49 | private: 50 | NetworkIO *nio; 51 | Tcp6Service *ss; 52 | json_object *conf; 53 | ConnectionManager *cm; 54 | int pidForUpdates; 55 | static map *handlers; 56 | 57 | public: 58 | /** 59 | * very similary to the other constructor, execpt config paramters are attempted 60 | * to be read from a properties object p 61 | * @param conn the connectionManager associated with this ManagerHelper 62 | * @param p a propertied object (config file) 63 | */ 64 | ManagerHelper(ConnectionManager *conn, json_object *conf); 65 | 66 | /** 67 | * instantiates a new ManagerHelper with default parameters, the ManagerHelper 68 | * facilitates getting server state information to the ServerManager 69 | * @param conn the connectionManager associated with this ManagerHelper 70 | */ 71 | ManagerHelper(ConnectionManager *conn); 72 | 73 | void shutdown(); 74 | 75 | private: 76 | void initCommon(); 77 | 78 | /** 79 | * send_data constructs the packet and sends it to the ServerManager 80 | * @param command the server command to send 81 | * @param obj the data relevant to be sent with command 82 | */ 83 | void send_data(const char *command, json_object *obj = NULL); 84 | 85 | /** 86 | * run kicks off a thread that perpetually waits for a single connection, if the connection is dropped 87 | * it waits again, once connected, the ManagerHelper processes commands similar to the server. 88 | */ 89 | static void *run(void *arg); 90 | 91 | /** 92 | * closes the socket 93 | */ 94 | void terminate(); 95 | 96 | static void mng_get_connections(json_object *obj, ManagerHelper *mh); 97 | static void mng_get_stats(json_object *obj, ManagerHelper *mh); 98 | static void mng_shutdown(json_object *obj, ManagerHelper *mh); 99 | static void mng_project_import(json_object *obj, ManagerHelper *mh); 100 | static void mng_import_update(json_object *obj, ManagerHelper *mh); 101 | static void mng_project_list(json_object *obj, ManagerHelper *mh); 102 | static void mng_project_export(json_object *obj, ManagerHelper *mh); 103 | 104 | void init_handlers(); 105 | 106 | public: 107 | void start(); 108 | 109 | bool done; 110 | bool quit; 111 | 112 | }; 113 | 114 | #endif 115 | 116 | 117 | -------------------------------------------------------------------------------- /database/init_database.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # these are user configurable - but you should prob them across all aux files # 4 | SERVICE_NAME=collabreate 5 | COLLAB_DB=collabDB 6 | COLLAB_CONF=server.conf 7 | IDENT="initdb" 8 | 9 | # these can also be set via exported environmental variables # 10 | # eg: >INSTALLDIR=/usr/local/collabreate/server # 11 | # >export INSTALLDIR # 12 | # >make install # 13 | # if you do set these via the environment, you should configure your system # 14 | # to always set them (other scripts depend upon the values of these variables)# 15 | COLLAB_SERVER_DIR="${COLLAB_SERVER_DIR:-/opt/collabreate/server}" 16 | COLLAB_LOG="${COLLAB_LOG:-/var/log/collab}" 17 | COLLAB_SCRIPT="${COLLAB_SCRIPT:-/usr/sbin/collabctl}" 18 | COLLAB_USER="${COLLAB_USER:-collab}" 19 | COLLAB_GROUP="${COLLAB_GROUP:-collab}" 20 | # end # 21 | 22 | # for those that actually use SELinux 23 | if [ -x "/sbin/runuser" ]; 24 | then 25 | SU="/sbin/runuser" 26 | else 27 | SU="su" 28 | fi 29 | 30 | USERADD=`which adduser` 31 | 32 | if [ -f "$COLLAB_SERVER_DIR/$COLLAB_CONF" ]; 33 | then 34 | LIKELYDB=`grep ^JDBC_NAME server.conf | grep -o "mysql\|postgresql"` 35 | echo "According to your installed server.conf file, you want to use: $LIKELYDB" 36 | echo "(if $LIKELYDB is not correct, you should exit and edit $COLLAB_SERVER_DIR/server.conf)" 37 | elif [ -f "$COLLAB_CONF" ]; 38 | then 39 | LIKELYDB=`grep ^JDBC_NAME server.conf | grep -o "mysql\|postgresql"` 40 | echo "According to your local server.conf file, you want to use: $LIKELYDB" 41 | echo "(if $LIKELYDB is not correct, you should exit and edit server.conf)" 42 | else 43 | LIKELYDB="postgresql" 44 | echo "Couldn't find your server.conf file, you really should have one..." 45 | fi 46 | 47 | echo "Select which database type you would like initialize for use with collabREate" 48 | OPTIONS="MySQL PostgreSQL Exit" 49 | select opt in $OPTIONS; do 50 | if [ "$opt" = "MySQL" ]; then 51 | echo "Initializing mysql..." 52 | echo "The account you are running as must have several mysql create permissions" 53 | echo "Do you want to continue ?" 54 | OPTIONS2="yes no" 55 | select opt2 in $OPTIONS2; do 56 | if [ "$opt2" = "yes" ]; then 57 | echo "adding user $COLLAB_USER" 58 | $SU -c "$USERADD $COLLAB_USER" 59 | mysql < mysql/dbschema.sql 60 | echo "MySQL collabreate initialization done" 61 | exit 62 | elif [ "$opt2" = "no" ]; then 63 | exit 64 | else 65 | echo "1 for 'yes' or 2 for 'no'" 66 | fi 67 | done 68 | exit 69 | elif [ "$opt" = "PostgreSQL" ]; then 70 | echo "adding user $COLLAB_USER" 71 | $SU -c "$USERADD $COLLAB_USER" 72 | echo "Initializing postgres..." 73 | #pg_hba.conf defaults to "ident sameuser" so -U doesn't work 74 | #however to su to users prior to psql commands, $COLLAB_USER must exist 75 | #as a local user....sigh, the follow attemps -U commands, then 76 | #falls back to su style commands 77 | createuser -U postgres -s -d -R $COLLAB_USER 78 | if [ $? -ne 0 ]; 79 | then 80 | $SU postgres -c "createuser -s -d -R $COLLAB_USER" 81 | fi 82 | createdb -U $COLLAB_USER $COLLAB_DB 83 | if [ $? -ne 0 ]; 84 | then 85 | $SU $COLLAB_USER -c "createdb $COLLAB_DB" 86 | fi 87 | psql -q -U $COLLAB_USER -d $COLLAB_DB -f postgresql/dbschema.sql 88 | if [ $? -ne 0 ]; 89 | then 90 | $SU $COLLAB_USER -c "psql -q -d $COLLAB_DB < postgresql/dbschema.sql" 91 | fi 92 | echo 93 | echo "Note:" 94 | echo "failures in the postgres init are usually due to issues" 95 | echo "with pg_hba.conf or system permissions" 96 | echo "ie 'ident sameuser' " 97 | exit 98 | elif [ "$opt" = "Exit" ]; then 99 | exit 100 | else 101 | echo "only options 1-3 are supported" 102 | fi 103 | done 104 | 105 | -------------------------------------------------------------------------------- /server/java/collabreate/server/install_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | COLLAB_SCRIPT="${COLLAB_SCRIPT:-/usr/sbin/collabctl}" 4 | COLLAB_LOG="${COLLAB_LOG:-/var/log/collab}" 5 | INSTALL_DIR=/opt/collabreate/server 6 | OPTIONS="Yes No" 7 | 8 | # for those that actually use SELinux 9 | if [ -x "/sbin/runuser" ]; then 10 | SU="/sbin/runuser" 11 | else 12 | SU="su" 13 | fi 14 | 15 | echo "this script will install the collabreate server." 16 | echo "Some options may require root privs (it might be easier to run this script as root)" 17 | echo "continue?" 18 | select o in $OPTIONS; do 19 | if [ "$o" = "Yes" ]; 20 | then 21 | if [ ! -f "$COLLAB_LOG" ]; 22 | then 23 | `$SU root -c "touch $COLLAB_LOG"` 24 | `$SU root -c "chgrp $COLLAB_USER $COLLAB_LOG"` 25 | `$SU root -c "chmod 0664 $COLLAB_LOG"` 26 | fi 27 | if [ ! -f "$COLLAB_SCRIPT" ]; 28 | then 29 | `$SU root -c "cp collabctl $COLLAB_SCRIPT"` 30 | `$SU root -c "chmod 0555 $COLLAB_SCRIPT"` 31 | fi 32 | if [ ! -f "collabreate_server.jar" ] && [ -f "build_jar.sh" ]; 33 | then 34 | echo "It looks like you haven't built the server jar file yet, should I try to build it?" 35 | select opt in $OPTIONS; do 36 | if [ "$opt" = "Yes" ]; 37 | then 38 | ./build_jar.sh 39 | break 40 | fi 41 | if [ "$opt" = "No" ]; 42 | then 43 | echo "the server jar is required for install, exiting" 44 | exit -1 45 | fi 46 | done 47 | fi 48 | 49 | if [ ! -f "server.conf" ]; 50 | then 51 | echo "It looks like you haven't created a server.conf, you really should have one." 52 | echo "the server may not run as expected without the server.conf file" 53 | fi 54 | 55 | if [ -f "collabreate_server.jar" ]; 56 | then 57 | echo "making directories" 58 | `$SU root -c "mkdir -p $INSTALL_DIR"` 59 | echo "copying server jar" 60 | `$SU root -c "cp collabreate_server.jar $INSTALL_DIR/collabreate_server.jar"` 61 | DBJAR=`ls *.jar | grep -i "mysql\|postgres"` 62 | for j in $DBJAR; do 63 | echo "copying db jar: $j" 64 | `$SU root -c "cp ./$j $INSTALL_DIR/"` 65 | done 66 | if [ -f "collabreate_manager.jar" ]; 67 | then 68 | echo "copying manager jar" 69 | `$SU root -c "cp collabreate_manager.jar $INSTALL_DIR/collabreate_manager.jar"` 70 | else 71 | echo "can't find manager jar file. It might not have built correctly." 72 | echo "continuing with install anyway - you won't be able to use the management interface." 73 | fi 74 | if [ ! -f $INSTALL_DIR"/server.conf" ]; 75 | then 76 | echo "copying server.conf" 77 | `$SU root -c "cp server.conf $INSTALL_DIR/server.conf"` 78 | else 79 | echo "Looks like you already have a server.conf installed, skipping" 80 | fi 81 | echo "do you want to install and configure init.d start/stop script? " 82 | select opt in $OPTIONS; do 83 | if [ "$opt" = "Yes" ]; 84 | then 85 | if [ -f "fedora-init.d-script" ]; 86 | then 87 | #quick check for fedora 88 | if [ -f "/etc/redhat-release" ] || [ -f "/etc/fedora-release" ]; 89 | then 90 | echo "copying init.d script to /etc/init.d/collabreate" 91 | `$SU root -c "cp fedora-init.d-script /etc/init.d/collabreate"` 92 | echo "changing permissions" 93 | `$SU root -c "chmod 755 /etc/init.d/collabreate"` 94 | echo "chkconfig collabreate" 95 | `$SU root -c "chkconfig --add collabreate"` 96 | else 97 | echo "looks like you're not using fedora, the init.d script may work for you, " 98 | echo "but you'll have to install it manually" 99 | fi 100 | fi 101 | exit 102 | fi 103 | if [ "$opt" = "No" ]; 104 | then 105 | exit 106 | fi 107 | done 108 | else 109 | echo "can't find server jar file. Did it build correctly?" 110 | echo "you might try to build the jar, see the README file" 111 | exit -1 112 | fi 113 | 114 | fi 115 | if [ "$o" = "No" ]; 116 | then 117 | exit 0 118 | fi 119 | done 120 | exit 0 121 | -------------------------------------------------------------------------------- /json-c/printbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: printbuf.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | * 11 | * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. 12 | * The copyrights to the contents of this file are licensed under the MIT License 13 | * (http://www.opensource.org/licenses/mit-license.php) 14 | */ 15 | 16 | /** 17 | * @file 18 | * @brief Internal string buffer handing. Unless you're writing a 19 | * json_object_to_json_string_fn implementation for use with 20 | * json_object_set_serializer() direct use of this is not 21 | * recommended. 22 | */ 23 | #ifndef _printbuf_h_ 24 | #define _printbuf_h_ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | struct printbuf { 31 | char *buf; 32 | int bpos; 33 | int size; 34 | }; 35 | typedef struct printbuf printbuf; 36 | 37 | extern struct printbuf* 38 | printbuf_new(void); 39 | 40 | /* As an optimization, printbuf_memappend_fast() is defined as a macro 41 | * that handles copying data if the buffer is large enough; otherwise 42 | * it invokes printbuf_memappend() which performs the heavy 43 | * lifting of realloc()ing the buffer and copying data. 44 | * 45 | * Your code should not use printbuf_memappend() directly unless it 46 | * checks the return code. Use printbuf_memappend_fast() instead. 47 | */ 48 | extern int 49 | printbuf_memappend(struct printbuf *p, const char *buf, int size); 50 | 51 | #define printbuf_memappend_fast(p, bufptr, bufsize) \ 52 | do { \ 53 | if ((p->size - p->bpos) > bufsize) { \ 54 | memcpy(p->buf + p->bpos, (bufptr), bufsize); \ 55 | p->bpos += bufsize; \ 56 | p->buf[p->bpos]= '\0'; \ 57 | } else { printbuf_memappend(p, (bufptr), bufsize); } \ 58 | } while (0) 59 | 60 | #define printbuf_length(p) ((p)->bpos) 61 | 62 | /** 63 | * Results in a compile error if the argument is not a string literal. 64 | */ 65 | #define _printbuf_check_literal(mystr) ("" mystr) 66 | 67 | /** 68 | * This is an optimization wrapper around printbuf_memappend() that is useful 69 | * for appending string literals. Since the size of string constants is known 70 | * at compile time, using this macro can avoid a costly strlen() call. This is 71 | * especially helpful when a constant string must be appended many times. If 72 | * you got here because of a compilation error caused by passing something 73 | * other than a string literal, use printbuf_memappend_fast() in conjunction 74 | * with strlen(). 75 | * 76 | * See also: 77 | * printbuf_memappend_fast() 78 | * printbuf_memappend() 79 | * sprintbuf() 80 | */ 81 | #define printbuf_strappend(pb, str) \ 82 | printbuf_memappend ((pb), _printbuf_check_literal(str), sizeof(str) - 1) 83 | 84 | /** 85 | * Set len bytes of the buffer to charvalue, starting at offset offset. 86 | * Similar to calling memset(x, charvalue, len); 87 | * 88 | * The memory allocated for the buffer is extended as necessary. 89 | * 90 | * If offset is -1, this starts at the end of the current data in the buffer. 91 | */ 92 | extern int 93 | printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len); 94 | 95 | /** 96 | * Formatted print to printbuf. 97 | * 98 | * This function is the most expensive of the available functions for appending 99 | * string data to a printbuf and should be used only where convenience is more 100 | * important than speed. Avoid using this function in high performance code or 101 | * tight loops; in these scenarios, consider using snprintf() with a static 102 | * buffer in conjunction with one of the printbuf_*append() functions. 103 | * 104 | * See also: 105 | * printbuf_memappend_fast() 106 | * printbuf_memappend() 107 | * printbuf_strappend() 108 | */ 109 | extern int 110 | sprintbuf(struct printbuf *p, const char *msg, ...); 111 | 112 | extern void 113 | printbuf_reset(struct printbuf *p); 114 | 115 | extern void 116 | printbuf_free(struct printbuf *p); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #Set this variable to point to your SDK directory 2 | IDA_SDK=../../ 3 | 4 | SDKVER=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7-) 5 | IDAVER=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7- | sed 's/\(.\)\(.\)/\1\.\2/') 6 | IDAVER_MAJOR=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7) 7 | 8 | PLATFORM=$(shell uname | cut -f 1 -d _) 9 | 10 | #Set this variable to the desired name of your compiled plugin 11 | PLUGIN=collabreate 12 | 13 | ifeq "$(PLATFORM)" "Linux" 14 | IDA=/opt/ida-$(IDAVER) 15 | HAVE_IDA64=$(shell if [ -f $(IDA)/libida64.so ]; then echo -n yes; fi) 16 | PLATFORM_CFLAGS=-D__LINUX__ 17 | PLATFORM_LDFLAGS=-shared -s 18 | IDADIR=-L$(IDA) 19 | 20 | ifeq "$(IDAVER_MAJOR)" "6" 21 | PLUGIN_EXT32=.plx 22 | PLUGIN_EXT64=.plx64 23 | else 24 | PLUGIN_EXT32=.so 25 | PLUGIN_EXT64=64.so 26 | endif 27 | 28 | IDALIB32=-lida 29 | IDALIB64=-lida64 30 | 31 | else ifeq "$(PLATFORM)" "Darwin" 32 | 33 | IDAHOME=/Applications/IDA Pro $(IDAVER) 34 | 35 | ifeq "$(IDAVER_MAJOR)" "6" 36 | IDA=$(shell dirname "`find "$(IDAHOME)" -name idaq | tail -n 1`") 37 | PLUGIN_EXT32=.pmc 38 | PLUGIN_EXT64=.pmc64 39 | else 40 | IDA=$(shell dirname "`find "$(IDAHOME)" -name ida | tail -n 1`") 41 | PLUGIN_EXT32=.dylib 42 | PLUGIN_EXT64=64.dylib 43 | endif 44 | 45 | HAVE_IDA64=$(shell find "$(IDA)" -name libida64.dylib -exec echo -n yes \;) 46 | PLATFORM_CFLAGS=-D__MAC__ 47 | PLATFORM_LDFLAGS=-dynamiclib 48 | IDADIR=-L"$(IDA)" 49 | 50 | IDALIB32=-lida 51 | IDALIB64=-lida64 52 | endif 53 | 54 | ifeq "$(IDAVER_MAJOR)" "6" 55 | CFLAGS=-Wextra -Os $(PLATFORM_CFLAGS) -m32 -fPIC 56 | LDFLAGS=$(PLATFORM_LDFLAGS) -m32 57 | else 58 | CFLAGS=-Wextra -Os $(PLATFORM_CFLAGS) -D__X64__ -m64 -fPIC 59 | LDFLAGS=$(PLATFORM_LDFLAGS) -m64 60 | endif 61 | 62 | ifeq ($(shell test $(SDKVER) -gt 72; echo $$?),0) 63 | CFLAGS+= -std=c++11 64 | endif 65 | 66 | #specify any additional libraries that you may need 67 | EXTRALIBS=-ljson-c 68 | 69 | # Destination directory for compiled plugins 70 | OUTDIR=./bin/ 71 | 72 | OBJDIR32=./obj32 73 | OBJDIR64=./obj64 74 | 75 | #list out the object files in your project here 76 | OBJS32= $(OBJDIR32)/collabreate.o $(OBJDIR32)/collabreate_common.o $(OBJDIR32)/ida_ui.o $(OBJDIR32)/idanet.o $(OBJDIR32)/collab_hooks.o $(OBJDIR32)/collab_msgs.o 77 | OBJS64= $(OBJDIR64)/collabreate.o $(OBJDIR64)/collabreate_common.o $(OBJDIR64)/ida_ui.o $(OBJDIR64)/idanet.o $(OBJDIR64)/collab_hooks.o $(OBJDIR64)/collab_msgs.o 78 | 79 | SRCS=collabreate.cpp collabreate_common.cpp ida_ui.cpp idanet.cpp collab_hooks.cpp collab_msgs.cpp 80 | 81 | BINARY32=$(OUTDIR)$(PLUGIN)$(PLUGIN_EXT32) 82 | BINARY64=$(OUTDIR)$(PLUGIN)$(PLUGIN_EXT64) 83 | 84 | ifdef HAVE_IDA64 85 | 86 | all: $(OUTDIR) $(BINARY32) $(BINARY64) 87 | 88 | clean: 89 | -@rm $(OBJDIR32)/*.o 90 | -@rm $(OBJDIR64)/*.o 91 | -@rm $(BINARY32) 92 | -@rm $(BINARY64) 93 | 94 | $(OBJDIR64): 95 | -@mkdir -p $(OBJDIR64) 96 | 97 | else 98 | 99 | all: $(OUTDIR) $(BINARY32) 100 | 101 | clean: 102 | -@rm $(OBJDIR32)/*.o 103 | -@rm $(BINARY32) 104 | 105 | endif 106 | 107 | $(OUTDIR): 108 | -@mkdir -p $(OUTDIR) 109 | 110 | $(OBJDIR32): 111 | -@mkdir -p $(OBJDIR32) 112 | 113 | CC=g++ 114 | #CC=clang 115 | INC=-I$(IDA_SDK)include/ -I/usr/local/include 116 | 117 | LD=g++ 118 | #LD=clang 119 | 120 | #%.o: %.cpp 121 | # $(CC) -c $(CFLAGS) $(INC) $< -o $@ 122 | 123 | $(OBJDIR32)/%.o: %.cpp 124 | $(CC) -c $(CFLAGS) $(INC) $< -o $@ 125 | 126 | $(BINARY32): $(OBJDIR32) $(OBJS32) 127 | $(LD) $(LDFLAGS) -o $@ $(CFLAGS) $(OBJS32) $(IDADIR) $(IDALIB32) $(EXTRALIBS) 128 | 129 | ifdef HAVE_IDA64 130 | 131 | $(OBJDIR64)/%.o: %.cpp 132 | $(CC) -c $(CFLAGS) -D__EA64__ $(INC) $< -o $@ 133 | 134 | $(BINARY64): $(OBJDIR64) $(OBJS64) 135 | $(LD) $(LDFLAGS) -o $@ $(OBJS64) $(IDADIR) $(IDALIB64) $(EXTRALIBS) 136 | 137 | endif 138 | 139 | #$(OBJDIR32)/collabreate.o: collabreate.cpp 140 | #$(OBJDIR32)/collabreate_common.o: collabreate_common.cpp 141 | #$(OBJDIR32)/ida_ui.o: ida_ui.cpp 142 | #$(OBJDIR32)/idanet.o: idanet.cpp 143 | #$(OBJDIR32)/collab_hooks.o: collab_hooks.cpp 144 | #$(OBJDIR32)/collab_msgs.o: collab_msgs.cpp 145 | 146 | #$(OBJDIR64)/collabreate.o: collabreate.cpp 147 | #$(OBJDIR64)/collabreate_common.o: collabreate_common.cpp 148 | #$(OBJDIR64)/ida_ui.o: ida_ui.cpp 149 | #$(OBJDIR64)/idanet.o: idanet.cpp 150 | #$(OBJDIR64)/collab_hooks.o: collab_hooks.cpp 151 | #$(OBJDIR64)/collab_msgs.o: collab_msgs.cpp 152 | 153 | collabreate.cpp: idanet.h collabreate.h 154 | collab_hooks.cpp: idanet.h collabreate.h 155 | collab_msgs.cpp: idanet.h collabreate.h 156 | collabreate_common.cpp: collabreate.h 157 | ida_ui.cpp: collabreate_ui.h idanet.h collabreate.h 158 | idanet.cpp: idanet.h collabreate.h 159 | -------------------------------------------------------------------------------- /server/c++/projectmap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate projectmap.cpp 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include "client.h" 22 | #include "projectmap.h" 23 | #include "clientset.h" 24 | 25 | ProjectMap::ProjectMap() { 26 | pthread_mutexattr_t attr; 27 | pthread_mutexattr_init(&attr); 28 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 29 | pthread_mutex_init(&mutex, &attr); 30 | pthread_mutexattr_destroy(&attr); 31 | } 32 | 33 | ProjectMap::~ProjectMap() { 34 | pthread_mutex_destroy(&mutex); 35 | } 36 | 37 | //iterate over all projects in the set 38 | void ProjectMap::loop(pcb func, void *user) { 39 | pthread_mutex_lock(&mutex); 40 | for (map::iterator i = projects.begin(); i != projects.end(); i++) { 41 | ClientSet *s = (*i).second; 42 | if (!(*func)(s, user)) { 43 | break; 44 | } 45 | } 46 | pthread_mutex_unlock(&mutex); 47 | } 48 | 49 | //loop across all clients in a single project 50 | void ProjectMap::loopProject(uint32_t key, ccb func, void *user) { 51 | ClientSet *s = get(key); 52 | if (s) { 53 | s->loop(func, user); 54 | } 55 | } 56 | 57 | //loop across all clients in all projects 58 | void ProjectMap::loopClients(ccb func, void *user) { 59 | pthread_mutex_lock(&mutex); 60 | for (map::iterator i = projects.begin(); i != projects.end(); i++) { 61 | ClientSet *s = (*i).second; 62 | s->loop(func, user); 63 | } 64 | pthread_mutex_unlock(&mutex); 65 | } 66 | 67 | //add a new project 68 | void ProjectMap::put(uint32_t key, ClientSet *val) { 69 | pthread_mutex_lock(&mutex); 70 | projects[key] = val; 71 | pthread_mutex_unlock(&mutex); 72 | } 73 | 74 | //call this only if you already hold a lock 75 | ClientSet *ProjectMap::getPriv(uint32_t key) { 76 | ClientSet *res = NULL; 77 | map::iterator it = projects.find(key); 78 | if (it != projects.end()) { 79 | res = (*it).second; 80 | } 81 | return res; 82 | } 83 | 84 | //add client to the given project 85 | void ProjectMap::addClient(uint32_t key, Client *c) { 86 | pthread_mutex_lock(&mutex); 87 | ClientSet *proj = getPriv(key); 88 | if (proj == NULL) { 89 | proj = new ClientSet; 90 | //already have a lock don't neet to call put 91 | projects[key] = proj; 92 | } 93 | proj->add(c); 94 | pthread_mutex_unlock(&mutex); 95 | } 96 | 97 | //add client to the given project 98 | void ProjectMap::addClient(Client *c) { 99 | pthread_mutex_lock(&mutex); 100 | ClientSet *proj = getPriv(c->getPid()); 101 | if (proj == NULL) { 102 | proj = new ClientSet; 103 | //already have a lock don't neet to call put 104 | projects[c->getPid()] = proj; 105 | } 106 | proj->add(c); 107 | pthread_mutex_unlock(&mutex); 108 | } 109 | 110 | //add client to the given project 111 | void ProjectMap::removeClient(Client *c) { 112 | pthread_mutex_lock(&mutex); 113 | ClientSet *proj = getPriv(c->getPid()); 114 | if (proj != NULL) { 115 | proj->remove(c); 116 | } 117 | pthread_mutex_unlock(&mutex); 118 | } 119 | 120 | //number of clients connected to the given project 121 | int ProjectMap::numClients(uint32_t key) { 122 | int res = 0; 123 | pthread_mutex_lock(&mutex); 124 | ClientSet *proj = getPriv(key); 125 | if (proj != NULL) { 126 | res = proj->size(); 127 | } 128 | pthread_mutex_unlock(&mutex); 129 | return res; 130 | } 131 | 132 | //get the list of clients connected to the given project 133 | //should this be a cloned set ?? probably 134 | ClientSet *ProjectMap::get(uint32_t key) { 135 | ClientSet *res = NULL; 136 | pthread_mutex_lock(&mutex); 137 | map::iterator it = projects.find(key); 138 | if (it != projects.end()) { 139 | res = (*it).second; 140 | } 141 | pthread_mutex_unlock(&mutex); 142 | return res; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /server/java/collabreate/server/collabctl: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | # 3 | # collabreate This is the server startup script for the CollabREate server 4 | # 5 | # chkconfig: 2345 96 04 6 | # description: CollabREate server 7 | 8 | ### BEGIN INIT INFO 9 | # Provides: collabreate 10 | # Required-Start: $local_fs $network $named postgresql 11 | # Required-Stop: $local_fs $network $named postgresql 12 | # Default-Start: 2 3 4 5 13 | # Default-Stop: 0 1 6 14 | # Short-Description: The collabreate server service 15 | # Description: collabreate is a collaborative reverse engineering tool 16 | ### END INIT INFO 17 | 18 | # these are user configurable - but you should prob them across all aux files # 19 | SERVICE_NAME=collabreate 20 | JAVA_OPTS="-verbose -jar" 21 | COLLAB_SERVER_JAR="collabreate_server.jar" 22 | COLLAB_MANAGER_JAR="collabreate_manager.jar" 23 | COLLAB_CONF="server.conf" 24 | IDENT="collabctl" 25 | PID_FILE=/var/run/"$SERVICE_NAME".pid 26 | PID="" 27 | 28 | # these can also be set via exported environmental variables # 29 | # eg: >INSTALLDIR=/usr/local/collabreate/server # 30 | # >export INSTALLDIR # 31 | # >make install # 32 | # if you do set these via the environment, you should configure your system # 33 | # to always set them (other scripts depend upon the values of these variables)# 34 | COLLAB_SERVER_DIR="${COLLAB_SERVER_DIR:-/opt/collabreate/server}" 35 | COLLAB_LOG="${COLLAB_LOG:-/var/log/collab}" 36 | COLLAB_SCRIPT="${COLLAB_SCRIPT:-/usr/sbin/collabctl}" 37 | COLLAB_USER="${COLLAB_USER:-collab}" 38 | # end # 39 | 40 | USER=`whoami` 41 | IDENT="$IDENT ($USER)" 42 | #uncomment to override 43 | JAVA_HOME=/etc/alternatives/jre 44 | 45 | #find java 46 | if [ -z "$JAVA_HOME" ]; 47 | then 48 | JAVA=`which java` 49 | if [ -n "$JAVA" ] ; 50 | then 51 | JAVA_BINDIR=`dirname ${JAVA}` 52 | JAVA_HOME="${JAVA_BINDIR}/.." 53 | fi 54 | if [ -z "$JAVA_HOME" ]; 55 | then 56 | echo "$IDENT No JAVA_HOME defined and no java found in PATH" 57 | exit 1 58 | fi 59 | fi 60 | 61 | JAVA_BIN="$JAVA_HOME"/bin/java 62 | JAVA_JAVAC="$JAVA_HOME"/bin/javac 63 | 64 | script_result=0 65 | 66 | pidof(){ 67 | PID=`ps ax | grep "$COLLAB_SERVER_JAR" |grep -v grep` 68 | PID=`echo $PID | cut -d" " -f1` 69 | } 70 | 71 | start(){ 72 | local pg 73 | cd "$COLLAB_SERVER_DIR" 74 | # this is ridiculous but can't get Fedora to start the service 75 | # properly otherwise because it is not waiting for postgres to 76 | # be up and running 77 | for (( i = 0; i < 3; i++ )) ; do 78 | pg=`netstat -anp --inet | grep postmaster` 79 | if [ -n "$pg" ] ; then 80 | break 81 | fi 82 | sleep 3 83 | done 84 | if [ $i -eq 3 ]; then 85 | echo "$0: Tired of waiting for postgres, quiting" 86 | exit 1 87 | fi 88 | echo "$IDENT : starting server!" 89 | "$JAVA_BIN" $JAVA_OPTS "$COLLAB_SERVER_JAR" "$COLLAB_CONF" >/dev/null 2>&1 < /dev/null & 90 | sleep 2 91 | pidof 92 | if [ -n "$PID" ] ; 93 | then 94 | echo "$PID" > "$PID_FILE" 95 | else 96 | script_result=1 97 | fi 98 | } 99 | 100 | stop(){ 101 | cd "$COLLAB_SERVER_DIR" 102 | echo "$IDENT : stopping server!" 103 | "$JAVA_BIN" $JAVA_OPTS "$COLLAB_MANAGER_JAR" \ 104 | "$COLLAB_CONF" shutdown >/dev/null 2>&1 < /dev/null & 105 | rm -f "$PID_FILE" 106 | } 107 | 108 | kill(){ 109 | echo "$IDENT : killing server!" 110 | pidof 111 | if [ -n "$PID" ] ; 112 | then 113 | echo "$IDENT killing $PID" 114 | `kill -9 $PID` 115 | else 116 | echo "no server process found" 117 | fi 118 | rm -f "$PID_FILE" 119 | } 120 | 121 | restart(){ 122 | stop 123 | start 124 | } 125 | 126 | condrestart(){ 127 | [ -e "$PID_FILE" ] && restart || : 128 | } 129 | 130 | status(){ 131 | pidof 132 | if [ -n "$PID" ] ; 133 | then 134 | script_result=0 135 | elif [ -f "$PID_FILE" ] ; 136 | then 137 | script_result=1 138 | else 139 | script_result=3 140 | fi 141 | } 142 | 143 | reload(){ 144 | script_result=3 145 | } 146 | 147 | # See how we were called. 148 | case "$1" in 149 | start) 150 | start 151 | ;; 152 | stop) 153 | stop 154 | ;; 155 | status) 156 | status 157 | ;; 158 | restart) 159 | restart 160 | ;; 161 | condrestart|try-restart) 162 | condrestart 163 | ;; 164 | reload) 165 | reload 166 | ;; 167 | force-reload) 168 | restart 169 | ;; 170 | kill) 171 | kill 172 | ;; 173 | *) 174 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|kill}" 175 | exit 2 176 | esac 177 | 178 | exit $script_result 179 | -------------------------------------------------------------------------------- /database/postgresql/dbschema.sql: -------------------------------------------------------------------------------- 1 | -- IDA Pro Collabreation/Synchronization Plugin 2 | -- Copyright (C) 2008 Chris Eagle 3 | -- Copyright (C) 2008 Tim Vidas 4 | -- 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify it 7 | -- under the terms of the GNU General Public License as published by the Free 8 | -- Software Foundation; either version 2 of the License, or (at your option) 9 | -- any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, but WITHOUT 12 | -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | -- more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License along with 17 | -- this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | -- Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | -- postgresql JDBC driver is available here 21 | -- http://jdbc.postgresql.org/download.html 22 | 23 | --used to create the collabreate db in postgres, something like: 24 | -- createuser collab 25 | -- Not a superuser, but allow user to create databases 26 | -- createdb -U collab collabDB 27 | -- psql -U collab collabDB 28 | -- psql> \i dbschema.sql 29 | 30 | 31 | CREATE TABLE users ( 32 | userid SERIAL UNIQUE, 33 | username TEXT UNIQUE, 34 | pwhash TEXT, 35 | --some sort of general permissions (eg novice user) 36 | sub BIGINT, 37 | pub BIGINT, 38 | PRIMARY KEY(userid) 39 | ); 40 | 41 | CREATE SEQUENCE projects_pid_seq; 42 | 43 | CREATE TABLE projects ( 44 | pid SERIAL UNIQUE NOT NULL, --still want a local pid so that compares in update are fast 45 | gpid TEXT UNIQUE NOT NULL, --global pid across all instances of collabreate servers 46 | hash TEXT NOT NULL, 47 | description TEXT NOT NULL, 48 | created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 49 | touched TIMESTAMP, 50 | -- parent INTEGER, --for forked projects, should reference projects.pid 51 | owner TEXT REFERENCES users(username), 52 | --project permissions (initial creator of project is 'owner' - sets default perms) 53 | sub BIGINT, 54 | pub BIGINT, 55 | snapupdateid BIGINT DEFAULT 0, -- replaces entire snapshot table 56 | protocol INTEGER NOT NULL, --server protocol used to create this project 57 | PRIMARY KEY (pid) 58 | ); 59 | 60 | CREATE TABLE tablename ( 61 | colname integer NOT NULL DEFAULT nextval('projects_pid_seq') 62 | ); 63 | 64 | --ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname; 65 | 66 | CREATE INDEX projects_hash_index ON projects(hash); 67 | 68 | CREATE SEQUENCE updates_updateid_seq START 1; 69 | 70 | CREATE TABLE updates ( 71 | updateid BIGINT DEFAULT nextval('updates_updateid_seq') NOT NULL, 72 | username text REFERENCES users(username), 73 | pid INTEGER REFERENCES projects(pid) ON DELETE CASCADE, --pid not gpid for faster comparison 74 | cmd TEXT NOT NULL, 75 | json TEXT NOT NULL, 76 | created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 77 | PRIMARY KEY (updateid,pid) 78 | ); 79 | 80 | CREATE SEQUENCE snapshots_sid_seq; 81 | 82 | CREATE TABLE forklist ( 83 | fid SERIAL UNIQUE NOT NULL, 84 | child INTEGER REFERENCES projects(pid), 85 | parent INTEGER REFERENCES projects(pid), 86 | PRIMARY KEY(fid) 87 | ); 88 | --tracker is no longer required, since the last update is stored in the idb 89 | --CREATE TABLE tracker ( 90 | -- username TEXT references users(username), 91 | -- project INTEGER references projects(pid), 92 | -- updates INTEGER references updates(updateid), 93 | -- PRIMARY KEY (username, project, updates) 94 | --); 95 | 96 | CREATE LANGUAGE plpgsql; 97 | 98 | CREATE OR REPLACE FUNCTION next_project_id() RETURNS integer AS $$ 99 | BEGIN 100 | RETURN nextval('projects_pid_seq'); 101 | END; 102 | $$ LANGUAGE plpgsql; 103 | 104 | CREATE OR REPLACE FUNCTION fork_project(oldpid integer) RETURNS integer AS $$ 105 | DECLARE 106 | projects_row projects%ROWTYPE; 107 | newpid integer; 108 | BEGIN 109 | SELECT * INTO projects_row FROM projects WHERE pid = oldpid; 110 | newpid := next_project_id(); 111 | INSERT INTO projects VALUES(newpid, projects_row.hash); 112 | 113 | -- SELECT newpid, cmd, json FROM updates WHERE pid == oldpid AS fork_updates; 114 | -- INSERT INTO updates(pid, cmd, json) SELECT * from fork_updates; 115 | END; 116 | $$ LANGUAGE plpgsql; 117 | 118 | CREATE OR REPLACE FUNCTION copy_updates(ppid integer, maxid integer, lpid integer) RETURNS VOID AS $$ 119 | DECLARE 120 | BEGIN 121 | INSERT INTO updates (SELECT updateid,username,lpid,cmd,json,created FROM updates WHERE pid = ppid AND updateid <= maxid); 122 | END; 123 | $$ LANGUAGE plpgsql; 124 | 125 | --sample data 126 | --insert into users (username,pwhash) values ('someuser', MD5('SomePassword')); 127 | -------------------------------------------------------------------------------- /json-c/json_pointer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Alexadru Ardelean. 3 | * 4 | * This is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See COPYING for details. 6 | * 7 | */ 8 | 9 | /** 10 | * @file 11 | * @brief JSON Pointer (RFC 6901) implementation for retrieving 12 | * objects from a json-c object tree. 13 | */ 14 | #ifndef _json_pointer_h_ 15 | #define _json_pointer_h_ 16 | 17 | #include "json_object.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * Retrieves a JSON sub-object from inside another JSON object 25 | * using the JSON pointer notation as defined in RFC 6901 26 | * https://tools.ietf.org/html/rfc6901 27 | * 28 | * The returned JSON sub-object is equivalent to parsing manually the 29 | * 'obj' JSON tree ; i.e. it's not a new object that is created, but rather 30 | * a pointer inside the JSON tree. 31 | * 32 | * Internally, this is equivalent to doing a series of 'json_object_object_get()' 33 | * and 'json_object_array_get_idx()' along the given 'path'. 34 | * 35 | * Note that the 'path' string supports 'printf()' type arguments, so, whatever 36 | * is added after the 'res' param will be treated as an argument for 'path' 37 | * Example: json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar) 38 | * This means, that you need to escape '%' with '%%' (just like in printf()) 39 | * 40 | * @param obj the json_object instance/tree from where to retrieve sub-objects 41 | * @param path a (RFC6901) string notation for the sub-object to retrieve 42 | * @param res a pointer where to store a reference to the json_object 43 | * associated with the given path 44 | * 45 | * @return negative if an error (or not found), or 0 if succeeded 46 | */ 47 | int json_pointer_get(struct json_object *obj, const char *path, struct json_object **res); 48 | 49 | /** 50 | * This is a variant of 'json_pointer_get()' that supports printf() style arguments. 51 | * 52 | * Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, bak) 53 | * This also means that you need to escape '%' with '%%' (just like in printf()) 54 | * 55 | * Please take into consideration all recommended 'printf()' format security 56 | * aspects when using this function. 57 | * 58 | * @param obj the json_object instance/tree to which to add a sub-object 59 | * @param res a pointer where to store a reference to the json_object 60 | * associated with the given path 61 | * @param path_fmt a printf() style format for the path 62 | * 63 | * @return negative if an error (or not found), or 0 if succeeded 64 | */ 65 | int json_pointer_getf(struct json_object *obj, struct json_object **res, const char *path_fmt, ...); 66 | 67 | /** 68 | * Sets JSON object 'value' in the 'obj' tree at the location specified 69 | * by the 'path'. 'path' is JSON pointer notation as defined in RFC 6901 70 | * https://tools.ietf.org/html/rfc6901 71 | * 72 | * Note that 'obj' is a double pointer, mostly for the "" (empty string) 73 | * case, where the entire JSON object would be replaced by 'value'. 74 | * In the case of the "" path, the object at '*obj' will have it's refcount 75 | * decremented with 'json_object_put()' and the 'value' object will be assigned to it. 76 | * 77 | * For other cases (JSON sub-objects) ownership of 'value' will be transferred into 78 | * '*obj' via 'json_object_object_add()' & 'json_object_array_put_idx()', so the 79 | * only time the refcount should be decremented for 'value' is when the return value of 80 | * 'json_pointer_set()' is negative (meaning the 'value' object did not get set into '*obj'). 81 | * 82 | * That also implies that 'json_pointer_set()' does not do any refcount incrementing. 83 | * (Just that single decrement that was mentioned above). 84 | * 85 | * Note that the 'path' string supports 'printf()' type arguments, so, whatever 86 | * is added after the 'value' param will be treated as an argument for 'path' 87 | * Example: json_pointer_set(obj, "/foo/%d/%s", value, 0, bak) 88 | * This means, that you need to escape '%' with '%%' (just like in printf()) 89 | * 90 | * @param obj the json_object instance/tree to which to add a sub-object 91 | * @param path a (RFC6901) string notation for the sub-object to set in the tree 92 | * @param value object to set at path 93 | * 94 | * @return negative if an error (or not found), or 0 if succeeded 95 | */ 96 | int json_pointer_set(struct json_object **obj, const char *path, struct json_object *value); 97 | 98 | /** 99 | * This is a variant of 'json_pointer_set()' that supports printf() style arguments. 100 | * 101 | * Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, bak) 102 | * This also means that you need to escape '%' with '%%' (just like in printf()) 103 | * 104 | * Please take into consideration all recommended 'printf()' format security 105 | * aspects when using this function. 106 | * 107 | * @param obj the json_object instance/tree to which to add a sub-object 108 | * @param value object to set at path 109 | * @param path_fmt a printf() style format for the path 110 | * 111 | * @return negative if an error (or not found), or 0 if succeeded 112 | */ 113 | int json_pointer_setf(struct json_object **obj, struct json_object *value, const char *path_fmt, ...); 114 | 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /server/java/collabreate/server/ubuntu-init.d-script: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: collabREate 4 | # Required-Start: $local_fs $remote_fs $network 5 | # Required-Stop: $local_fs $remote_fs $network 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Start collabREate 9 | # Description: collabREate server daemon. Collaborative point for collabREating with IDA Pro. 10 | ### END INIT INFO 11 | 12 | # /etc/init.d/collabREate -- startup script for the collabREate collaboration engine for IDA Pro 13 | # Written By William Bartell 14 | # Based on fedora-init.d-script by Tim Vidas tvidasgmail[dot]com 15 | # Based on Ubuntu skeleton /etc/init.d/skeleton 16 | 17 | # PATH should only include /usr/* if it runs after the mountnfs.sh script 18 | PATH=/sbin:/usr/sbin:/bin:/usr/bin 19 | DESC="CollabREate server Daemon:" 20 | NAME=collabREate 21 | DAEMON=/usr/bin/java 22 | COLLAB_BASE=/var/collabreate 23 | JARFILE=$COLLAB_BASE/server/collabreate_server.jar 24 | DAEMON_ARGS="-jar $JARFILE $COLLAB_BASE/server/server.conf" 25 | PIDFILE=/var/run/$NAME.pid 26 | SCRIPTNAME=/etc/init.d/$NAME 27 | STOP_COMMAND="$DAEMON -jar $COLLAB_BASE/server/collabreate_manager.jar $COLLAB_BASE/server/server.conf shutdown" 28 | 29 | # Exit if the package is not installed 30 | [ -x "$DAEMON" ] || exit 0 31 | 32 | if [ `id -u` -ne 0 ]; then 33 | echo "You need root privileges to run this script" 34 | exit 1 35 | fi 36 | 37 | # Read configuration variable file if it is present 38 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME 39 | 40 | # Load the VERBOSE setting and other rcS variables 41 | . /lib/init/vars.sh 42 | 43 | # Define LSB log_* functions. 44 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 45 | . /lib/lsb/init-functions 46 | 47 | # 48 | # Function that retrieves the pid 49 | # 50 | get_pid() 51 | { 52 | #get the pid 53 | the_pid=-1 54 | 55 | if [ -e $PIDFILE ] 56 | then 57 | read the_pid < $PIDFILE 58 | else # go find it myself 59 | the_pid=`ps ax | grep "$DAEMON $DAEMON_ARGS" | grep -v grep | awk '{print $1}'` 60 | echo $the_pid > $PIDFILE 61 | fi 62 | return $the_pid 63 | } 64 | 65 | # 66 | # Function that checks if the daemon is running 67 | # utilzing get_pid() 68 | # 69 | is_running() 70 | { 71 | get_pid 72 | # if it's running. 73 | if [ -d "/proc/$?" ] # or kill -0 $pid? 74 | then 75 | return 1; 76 | else 77 | return 0; 78 | fi 79 | } 80 | 81 | # 82 | # Function that starts the daemon/service 83 | # 84 | do_start() 85 | { 86 | # Return 87 | # 0 if daemon has been started 88 | # 1 if daemon was already running 89 | # 2 if daemon could not be started 90 | is_running 91 | if [ $? -eq 1 ] 92 | then 93 | return 1; 94 | fi 95 | 96 | 97 | # test then start daemon 98 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ 99 | || return 1 100 | start-stop-daemon --start --make-pidfile --quiet --background --pidfile $PIDFILE --exec $DAEMON -- \ 101 | $DAEMON_ARGS \ 102 | || return 2 103 | sleep 2 104 | 105 | # if it's running. 106 | is_running 107 | if [ $? -eq 1 ] 108 | then 109 | return 0; 110 | else 111 | if [ -e $PIDFILE ] 112 | then 113 | rm -f $PIDFILE 114 | fi 115 | return 2; 116 | fi 117 | } 118 | 119 | # 120 | # Function that stops the daemon/service 121 | # 122 | do_stop() 123 | { 124 | # Return 125 | # 0 if daemon has been stopped 126 | # 1 if daemon was already stopped 127 | # 2 if daemon could not be stopped 128 | # other if a failure occurred 129 | 130 | #return an error state if it isn't changed later 131 | RETVAL=3 132 | 133 | # first try and do a safe shutdown 134 | is_running 135 | if [ $? -eq 1 ] 136 | then 137 | $STOP_COMMAND >/dev/null 2>&1 138 | sleep 2 139 | else 140 | RETVAL=1 141 | fi 142 | 143 | # if that fails be mean 144 | is_running 145 | if [ $? -eq 1 -a $RETVAL -eq 3 ] 146 | then 147 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME 148 | RETVAL="$?" 149 | #if we couldn't stop the deamon, then no reason to continue and remove the pidfile 150 | [ "$RETVAL" = 2 ] && return 2 151 | sleep 2 152 | else 153 | RETVAL=0; 154 | fi 155 | 156 | # Many daemons don't delete their pidfiles when they exit. 157 | if [ -e $PIDFILE ] 158 | then 159 | rm -f $PIDFILE 160 | fi 161 | return "$RETVAL" 162 | } 163 | 164 | case "$1" in 165 | start) 166 | log_daemon_msg "Starting $DESC" "$NAME" 167 | do_start 168 | case "$?" in 169 | 0|1) log_end_msg 0 ;; 170 | 2) log_end_msg 1 ;; 171 | *) log_end_msg 255 ;; 172 | esac 173 | ;; 174 | stop) 175 | log_daemon_msg "Stopping $DESC" "$NAME" 176 | do_stop 177 | case "$?" in 178 | 0|1) log_end_msg 0 ;; 179 | 2) log_end_msg 1 ;; 180 | *) log_end_msg 255 ;; 181 | esac 182 | ;; 183 | restart|force-reload) 184 | log_daemon_msg "Restarting $DESC" "$NAME" 185 | do_stop 186 | case "$?" in 187 | 0|1) 188 | do_start 189 | case "$?" in 190 | 0) log_end_msg 0 ;; 191 | 1) log_end_msg 1 ;; # Old process is still running 192 | *) log_end_msg 1 ;; # Failed to start 193 | esac 194 | ;; 195 | *) 196 | # Failed to stop 197 | log_end_msg 1 198 | ;; 199 | esac 200 | ;; 201 | *) 202 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 203 | exit 3 204 | ;; 205 | esac 206 | 207 | : 208 | -------------------------------------------------------------------------------- /database/mysql/dbschema.sql: -------------------------------------------------------------------------------- 1 | -- IDA Pro Collabreation/Synchronization Plugin 2 | -- Copyright (C) 2008 Chris Eagle 3 | -- Copyright (C) 2008 Tim Vidas 4 | -- 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify it 7 | -- under the terms of the GNU General Public License as published by the Free 8 | -- Software Foundation; either version 2 of the License, or (at your option) 9 | -- any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, but WITHOUT 12 | -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | -- more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License along with 17 | -- this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | -- Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | -- mysql JDBC driver is available here 21 | -- http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.6.tar.gz/from/pick#mirrors 22 | 23 | -- used to create the collabreate db in mysql, something like: 24 | 25 | CREATE DATABASE IF NOT EXISTS collabDB; 26 | 27 | use collabDB; 28 | 29 | CREATE TABLE users ( 30 | userid INT AUTO_INCREMENT UNIQUE, 31 | username TEXT UNIQUE, 32 | pwhash TEXT, 33 | -- some sort of general permissions (eg novice user) 34 | sub BIGINT, 35 | pub BIGINT, 36 | PRIMARY KEY(userid) 37 | ) ENGINE=InnoDB ; 38 | 39 | 40 | CREATE TABLE projects ( 41 | pid INT AUTO_INCREMENT UNIQUE NOT NULL, -- still want a local pid so that compares in update are fast 42 | gpid TEXT UNIQUE NOT NULL, -- global pid across all instances of collabreate servers 43 | hash TEXT NOT NULL, 44 | description TEXT NOT NULL, 45 | created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 46 | touched TIMESTAMP, 47 | owner TEXT REFERENCES users(username), 48 | -- project permissions (initial creator of project is 'owner' - sets default perms) 49 | sub BIGINT, 50 | pub BIGINT, 51 | snapupdateid BIGINT, -- replaces entire snapshot table 52 | protocol INTEGER NOT NULL, 53 | PRIMARY KEY (pid) 54 | ) ENGINE=InnoDB; 55 | 56 | CREATE INDEX projects_hash_index ON projects(hash); 57 | 58 | CREATE TABLE updateid ( 59 | seq bigint 60 | ); 61 | 62 | INSERT INTO updateid values(1); 63 | 64 | delimiter // 65 | CREATE FUNCTION nextid() RETURNS BIGINT 66 | BEGIN 67 | DECLARE temp BIGINT; 68 | SELECT seq into temp FROM updateid; 69 | UPDATE updateid SET seq = temp + 1; 70 | RETURN temp; 71 | END; 72 | // 73 | delimiter ; 74 | 75 | CREATE TABLE updates ( 76 | updateid BIGINT NOT NULL, -- DOES NOT WORK! can't assign default as the result of a function 77 | username TEXT REFERENCES users(username), 78 | pid INTEGER REFERENCES projects(pid), -- pid not gpid for faster comparison 79 | cmd TEXT NOT NULL, 80 | json TEXT NOT NULL, 81 | created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 82 | PRIMARY KEY (updateid,pid) 83 | ) ENGINE=InnoDB; 84 | 85 | delimiter // 86 | CREATE FUNCTION insertUpdate(_user TEXT, proj_id INTEGER, command TEXT, value TEXT) RETURNS BIGINT 87 | BEGIN 88 | DECLARE temp BIGINT; 89 | SELECT nextid() INTO temp; 90 | INSERT INTO updates (updateid,username,pid,cmd,json) VALUES (temp, _user, proj_id, command, value); 91 | RETURN temp; 92 | END; 93 | // 94 | delimiter ; 95 | 96 | delimiter // 97 | CREATE PROCEDURE copyUpdates(old_pid int, max_update int, new_pid int) 98 | BEGIN 99 | CREATE TEMPORARY TABLE tmptable (LIKE updates); 100 | INSERT INTO tmptable SELECT * FROM updates WHERE pid = old_pid AND updateid <= max_update; 101 | UPDATE tmptable SET pid = new_pid; 102 | INSERT INTO updates (SELECT * FROM tmptable); 103 | DROP TABLE tmptable; 104 | END; 105 | // 106 | delimiter ; 107 | 108 | CREATE TABLE forklist ( 109 | fid INT AUTO_INCREMENT UNIQUE NOT NULL, 110 | child INTEGER REFERENCES projects(pid), 111 | parent INTEGER REFERENCES projects(pid), 112 | PRIMARY KEY(fid) 113 | ) ENGINE=InnoDB; 114 | 115 | delimiter // 116 | CREATE FUNCTION addUserQuery(user TEXT, pw TEXT, p BIGINT, s BIGINT) RETURNS INTEGER 117 | BEGIN 118 | insert into users (username,pwhash,pub,sub) values (user, pw, p, s); 119 | return LAST_INSERT_ID(); 120 | END; 121 | // 122 | 123 | CREATE FUNCTION updateUserQuery(user TEXT, pw TEXT, p BIGINT, s BIGINT, uid INTEGER) RETURNS INTEGER 124 | BEGIN 125 | update users set username=user,pwhash=pw,pub=p,sub=s where userid=uid; 126 | return LAST_INSERT_ID(); 127 | END; 128 | // 129 | 130 | CREATE FUNCTION addProjectQuery(hash TEXT, gpid TEXT, descr text, owner int, p BIGINT, s BIGINT, protocol INTEGER) RETURNS INTEGER 131 | BEGIN 132 | insert into projects (hash,gpid,description,owner,pub,sub,protocol) values (hash, gpid, descr, owner, p, s, protocol); 133 | return LAST_INSERT_ID(); 134 | END; 135 | // 136 | 137 | CREATE FUNCTION addProjectSnapQuery(hash TEXT, gpid TEXT, descr text, owner int, snapid BIGINT, protocol INTEGER) RETURNS INTEGER 138 | BEGIN 139 | insert into projects (hash,gpid,description,owner,snapupdateid,protocol) values (hash, gpid, descr, owner, snapid, protocol); 140 | return LAST_INSERT_ID(); 141 | END; 142 | // 143 | 144 | CREATE FUNCTION addProjectForkQuery(child int, parent int) RETURNS INTEGER 145 | BEGIN 146 | insert into forklist (child,parent) values (child, parent); 147 | return LAST_INSERT_ID(); 148 | END; 149 | // 150 | delimiter ; 151 | 152 | CREATE USER collab IDENTIFIED BY 'collabpass'; 153 | GRANT ALL on collabDB.* to 'collab'@'%'; 154 | GRANT SELECT ON mysql.proc to 'collab'@'%'; 155 | -------------------------------------------------------------------------------- /server/java/collabreate/server/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate Utils 3 | Copyright (C) 2008 Chris Eagle 4 | Copyright (C) 2008 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | package collabreate.server; 22 | 23 | import java.security.*; 24 | 25 | /** 26 | * Utils 27 | * This class offers various utility functions used by the server 28 | * @author Tim Vidas 29 | * @author Chris Eagle 30 | * @version 0.2.0, January 2017 31 | */ 32 | 33 | public class Utils { 34 | 35 | private static SecureRandom srand = new SecureRandom(); 36 | 37 | /** 38 | * toHexString - generate a hex string representation of the specified 39 | * portion of the given array 40 | * @param data The array to be converted 41 | * @param start The starting index within the array 42 | * @param length The number of bytes to represent 43 | * @return The string representation of the given array 44 | */ 45 | protected static String toHexString(byte[] data, int start, int length) { 46 | String hex = ""; 47 | int end = start + length; 48 | for (int i = start; i < end; i++) { 49 | //need to ensure that we have a leading zero for bytes < 0x10 50 | String val = "0" + Integer.toHexString(data[i]); 51 | hex += val.substring(val.length() - 2); 52 | } 53 | return hex; 54 | } 55 | 56 | /** 57 | * toHexString - generate a hex string representation of the given array 58 | * @param data The array to be converted 59 | * @return The string representation of the given array 60 | */ 61 | protected static String toHexString(byte[] data) { 62 | return toHexString(data, 0, data.length); 63 | } 64 | 65 | /** 66 | * toHexString - generate a byte array representation of the specified 67 | * string 68 | * @param hexString The string to convert 69 | * @return The byte array representation of the given string 70 | */ 71 | protected static byte[] toByteArray(String hexString) { 72 | if ((hexString.length() % 2) == 1) { 73 | //invalid hex string 74 | return null; 75 | } 76 | try { 77 | int idx = 0; 78 | byte result[] = new byte[hexString.length() / 2]; 79 | for (int i = 0; i < hexString.length(); i += 2) { 80 | String val = hexString.substring(i, i + 2); 81 | int b = Integer.parseInt(val, 16); 82 | result[idx++] = (byte)b; 83 | } 84 | return result; 85 | } catch (Exception ex) { 86 | return null; 87 | } 88 | } 89 | 90 | /** 91 | * getMD5 - calculate the md5sum of a string 92 | * @param tohash The string to hash 93 | * @return The md5sum of the input string 94 | */ 95 | protected static String getMD5(String tohash) { 96 | byte[] defaultBytes = tohash.getBytes(); 97 | String hashString = ""; 98 | try { 99 | MessageDigest md5 = MessageDigest.getInstance("MD5"); 100 | md5.reset(); 101 | md5.update(defaultBytes); 102 | byte hash[] = md5.digest(); 103 | hashString = Utils.toHexString(hash); 104 | } catch(NoSuchAlgorithmException nsae) { 105 | } 106 | return hashString; 107 | } 108 | 109 | /** 110 | * getRandom Return an array of random bytes 111 | * @param len The number of bytes to return 112 | */ 113 | protected static byte[] getRandom(int len) { 114 | byte result[] = new byte[len]; 115 | srand.nextBytes(result); 116 | return result; 117 | } 118 | 119 | /** 120 | * tests if the provided string contains digits only 121 | * @param s string to test 122 | */ 123 | protected static boolean isNumeric(String s) { 124 | boolean rval = true; 125 | if (s == null || s.length() == 0) { 126 | rval = false; 127 | } 128 | else { 129 | for (int i = 0; i < s.length(); i++) { 130 | if (!Character.isDigit(s.charAt(i))) { 131 | rval = false; 132 | } 133 | } 134 | } 135 | return rval; 136 | } 137 | 138 | /** 139 | * tests if the provided string contains hex characters only 140 | * @param s string to test 141 | */ 142 | protected static boolean isHex(String s) { 143 | boolean rval = true; 144 | if (s == null || s.length() == 0) { 145 | rval = false; 146 | } 147 | else { 148 | final String abcdef = "abcdef"; 149 | for (int i = 0; i < s.length(); i++) { 150 | char c = Character.toLowerCase(s.charAt(i)); 151 | if (!(Character.isDigit(c) || (abcdef.indexOf(c) > -1))) { 152 | System.out.println("case 2" + c); 153 | rval = false; 154 | } 155 | } 156 | } 157 | return rval; 158 | } 159 | 160 | /** 161 | * tests if the provided string contains letters and digits only 162 | * @param s string to test 163 | */ 164 | protected static boolean isAlphaNumeric(String s) { 165 | boolean rval = true; 166 | if (s == null || s.length() == 0) { 167 | rval = false; 168 | } 169 | else { 170 | for (int i = 0; i < s.length(); i++) { 171 | if (!Character.isLetterOrDigit(s.charAt(i))) { 172 | rval = false; 173 | } 174 | } 175 | } 176 | return rval; 177 | } 178 | 179 | } 180 | 181 | -------------------------------------------------------------------------------- /json-c/config.h: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Enable RDRANR Hardware RNG Hash Seed */ 4 | #undef ENABLE_RDRAND 5 | 6 | /* Define if .gnu.warning accepts long strings. */ 7 | #undef HAS_GNU_WARNING_LONG 8 | 9 | /* Define to 1 if you have the declaration of `INFINITY', and to 0 if you 10 | don't. */ 11 | #if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) 12 | #define HAVE_DECL_INFINITY 1 13 | #endif 14 | 15 | /* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. 16 | */ 17 | #if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) 18 | #define HAVE_DECL_ISINF 1 19 | #endif 20 | 21 | /* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. 22 | */ 23 | #if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) 24 | #define HAVE_DECL_ISNAN 1 25 | #endif 26 | 27 | /* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */ 28 | #if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__) 29 | #define HAVE_DECL_NAN 1 30 | #endif 31 | 32 | /* Define to 1 if you have the declaration of `_finite', and to 0 if you 33 | don't. */ 34 | #define HAVE_DECL__FINITE 1 35 | 36 | /* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't. 37 | */ 38 | #define HAVE_DECL__ISNAN 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_DLFCN_H 1 42 | 43 | /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 44 | #define HAVE_DOPRNT 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #undef HAVE_ENDIAN_H 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_FCNTL_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_INTTYPES_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_LIMITS_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_LOCALE_H 1 60 | 61 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 62 | to 0 otherwise. */ 63 | #define HAVE_MALLOC 1 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #define HAVE_MEMORY_H 1 67 | 68 | /* Define to 1 if you have the `open' function. */ 69 | #define HAVE_OPEN 1 70 | 71 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 72 | and to 0 otherwise. */ 73 | #define HAVE_REALLOC 1 74 | 75 | /* Define to 1 if you have the `setlocale' function. */ 76 | #define HAVE_SETLOCALE 1 77 | 78 | /* Define to 1 if you have the `snprintf' function. */ 79 | #if defined(__MINGW32__) 80 | #define HAVE_SNPRINTF 1 81 | #else 82 | #undef HAVE_SNPRINTF 83 | #endif 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_STDARG_H 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_STDINT_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_STDLIB_H 1 93 | 94 | /* Define to 1 if you have the `strcasecmp' function. */ 95 | #define HAVE_STRCASECMP 1 96 | 97 | /* Define to 1 if you have the `strdup' function. */ 98 | #define HAVE_STRDUP 0 99 | 100 | /* Define to 1 if you have the `strerror' function. */ 101 | #define HAVE_STRERROR 1 102 | 103 | /* Define to 1 if you have the header file. */ 104 | #undef HAVE_STRINGS_H 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #define HAVE_STRING_H 1 108 | 109 | /* Define to 1 if you have the `strncasecmp' function. */ 110 | #if defined(__MINGW32__) 111 | #define HAVE_STRNCASECMP 1 112 | #else 113 | #undef HAVE_STRNCASECMP 114 | #endif 115 | 116 | //#cmakedefine HAVE_STRTOLL 117 | //#cmakedefine strtoll @cmake_strtoll@ 118 | 119 | /* Define to 1 if you have the header file. */ 120 | #undef HAVE_SYSLOG_H 121 | 122 | /* Define to 1 if you have the header file. */ 123 | #define HAVE_SYS_CDEFS_H 1 124 | 125 | /* Define to 1 if you have the header file. */ 126 | #if defined(__MINGW32__) 127 | #define HAVE_SYS_PARAM_H 1 128 | #else 129 | #undef HAVE_SYS_PARAM_H 130 | #endif 131 | 132 | /* Define to 1 if you have the header file. */ 133 | #define HAVE_SYS_STAT_H 1 134 | 135 | /* Define to 1 if you have the header file. */ 136 | #define HAVE_SYS_TYPES_H 1 137 | 138 | /* Define to 1 if you have the header file. */ 139 | #if defined(__MINGW32__) 140 | #define HAVE_UNISTD_H 1 141 | #else 142 | #undef HAVE_UNISTD_H 143 | #endif 144 | 145 | /* Define to 1 if you have the `vasprintf' function. */ 146 | #if defined(__MINGW32__) 147 | #define HAVE_VASPRINTF 1 148 | #else 149 | #undef HAVE_VASPRINTF 150 | #endif 151 | 152 | /* Define to 1 if you have the `vprintf' function. */ 153 | #define HAVE_VPRINTF 1 154 | 155 | /* Define to 1 if you have the `vsnprintf' function. */ 156 | #define HAVE_VSNPRINTF 1 157 | 158 | /* Define to 1 if you have the `vsyslog' function. */ 159 | #undef HAVE_VSYSLOG 160 | 161 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 162 | */ 163 | #undef LT_OBJDIR 164 | 165 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 166 | /* #undef NO_MINUS_C_MINUS_O */ 167 | 168 | /* Name of package */ 169 | #define PACKAGE "json-c" 170 | 171 | /* Define to the address where bug reports for this package should be sent. */ 172 | #define PACKAGE_BUGREPORT "json-c@googlegroups.com" 173 | 174 | /* Define to the full name of this package. */ 175 | #define PACKAGE_NAME "JSON C Library" 176 | 177 | /* Define to the full name and version of this package. */ 178 | #define PACKAGE_STRING "JSON C Library 0.13.99" 179 | 180 | /* Define to the one symbol short name of this package. */ 181 | #define PACKAGE_TARNAME "json-c" 182 | 183 | /* Define to the home page for this package. */ 184 | #define PACKAGE_URL "https://github.com/json-c/json-c" 185 | 186 | /* Define to the version of this package. */ 187 | #define PACKAGE_VERSION "0.13.99" 188 | 189 | /* Define to 1 if you have the ANSI C header files. */ 190 | #define STDC_HEADERS 1 191 | 192 | /* Version number of package */ 193 | #define VERSION "0.13.99" 194 | 195 | /* Define to empty if `const' does not conform to ANSI C. */ 196 | /* #undef const */ 197 | 198 | /* Define to rpl_malloc if the replacement function should be used. */ 199 | /* #undef malloc */ 200 | 201 | /* Define to rpl_realloc if the replacement function should be used. */ 202 | /* #undef realloc */ 203 | 204 | /* Define to `unsigned int' if does not define. */ 205 | /* #undef size_t */ 206 | -------------------------------------------------------------------------------- /server/java/collabreate/server/fedora-init.d-script: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # /etc/rc.d/init.d/collabreate 4 | # 5 | # This controls the collabREate server component. 6 | # You must have java jre, and for database mode a 7 | # database mysql|postgresql, and the appropriate 8 | # jdbc connector installed and configured. 9 | # See the collabREate README for more information. 10 | # 11 | # Author: Tim Vidas tvidasgmail[dot]com 12 | # 13 | # chkconfig: 2345 99 99 14 | # description: collabREate server daemon. Provides central \ 15 | # collaborative point for those collabREating with IDA Pro. 16 | # 17 | # this file is based on the init.d sample script provided with fedora 18 | # it can be found at: /usr/share/doc/initscripts-####/sysvinitfiles 19 | # 20 | # to use this script, copy it to /etc/init.d/collabreate (or /etc/rc.d/init.d) 21 | 22 | # Source function library. 23 | . /etc/init.d/functions 24 | 25 | # these are user configurable - but you should prob them across all aux files # 26 | SERVICE_NAME=collabreate 27 | JAVA_OPTS="-verbose -jar" 28 | COLLAB_SERVER_JAR="collabreate_server.jar" 29 | COLLAB_MANAGER_JAR="collabreate_manager.jar" 30 | COLLAB_CONF="server.conf" 31 | IDENT="collab>" 32 | PID_FILE=/var/run/$SERVICE_NAME.pid 33 | 34 | # these can also be set via exported environmental variables # 35 | # eg: >INSTALLDIR=/usr/local/collabreate/server # 36 | # >export INSTALLDIR # 37 | # >make install # 38 | # if you do set these via the environment, you should configure your system # 39 | # to always set them (other scripts depend upon the values of these variables)# 40 | COLLAB_SERVER_DIR="${COLLAB_SERVER_DIR:-/opt/collabreate/server}" 41 | COLLAB_LOG="${COLLAB_LOG:-/var/log/collab}" 42 | COLLAB_SCRIPT="${COLLAB_SCRIPT:-/usr/sbin/collabctl}" 43 | COLLAB_USER="${COLLAB_USER:-collab}" 44 | COLLAB_GROUP="${COLLAB_GROUP:-collab}" 45 | # end # 46 | 47 | #might be more portable: 48 | #if [ -z "$COLLAB_USER" ]; 49 | #then 50 | # COLLAB_USER=collab 51 | #fi 52 | 53 | #uncomment to override 54 | JAVA_HOME=/etc/alternatives/java_sdk 55 | 56 | #find java 57 | if [ -z "$JAVA_HOME" ]; 58 | then 59 | JAVA=`which java` 60 | if [ -n "$JAVA" ] ; 61 | then 62 | JAVA_BINDIR=`dirname ${JAVA}` 63 | JAVA_HOME="${JAVA_BINDIR}/.." 64 | fi 65 | if [ -z "$JAVA_HOME" ]; 66 | then 67 | echo "No JAVA_HOME defined and no java found in PATH" 68 | exit 1 69 | else 70 | echo "Found JAVA_HOME: ${JAVA_HOME}" 71 | echo "Please configure JAVA_HOME so I don't have to look for it next time" 72 | fi 73 | fi 74 | 75 | `export JAVA_HOME` 76 | 77 | JAVA_BIN="$JAVA_HOME"/bin/java 78 | JAVA_JAVAC="$JAVA_HOME"/bin/javac 79 | 80 | 81 | # for those that actually use SELinux 82 | if [ -x "/sbin/runuser" ]; 83 | then 84 | SU="/sbin/runuser" 85 | else 86 | SU="su" 87 | fi 88 | 89 | 90 | #DAEMON="$JAVA_BIN -jar ./collabreate_server.jar ./server.conf >/dev/null 2>&1 &" 91 | #SHUTDOWNAPP="$JAVA_BIN -jar ./collabreate_manager.jar ./server.conf shutdown" 92 | 93 | 94 | start() { 95 | echo -n "Starting collabreate server: " 96 | echo "(init.d) start recieved " >> $COLLAB_LOG 97 | apid=$(pgrep -u $COLLAB_USER java) 98 | if checkpid $apid 2>&1; 99 | then 100 | failure 101 | echo 102 | echo " Sever appears already be running: pid $apid" 103 | return -1 104 | else 105 | #echo "$SU - $COLLAB_USER -c "$COLLAB_SCRIPT start" >> $COLLAB_LOG 2>&1" 106 | `$SU - $COLLAB_USER -c "$COLLAB_SCRIPT start" >> $COLLAB_LOG 2>&1` 107 | RETVAL=$? 108 | if [ $RETVAL -eq 0 ]; 109 | then 110 | TPID=$(pgrep -u $COLLAB_USER java) 111 | `echo -n $TPID > $PID_FILE` 112 | `touch /var/lock/subsys/collabreate` 113 | `chown ${COLLAB_USER}:${COLLAB_USER} $PID_FILE` 114 | success 115 | echo 116 | else 117 | failure 118 | echo 119 | return -1 120 | fi 121 | fi 122 | 123 | return 0 124 | } 125 | 126 | stop() { 127 | echo -n "Shutting down collabreate server: " 128 | echo "(init.d) stop recieved " >> $COLLAB_LOG 129 | #check for pid started from this script: 130 | if [ -f $PID_FILE ]; 131 | then 132 | #killproc would have to be something like "killproc java" which may not be very nice 133 | #kill the 'correct' program, using kill instead of killproc 134 | read kpid < $PID_FILE 135 | 136 | #first try to 'safely' shutdown the server using the management application 137 | `$SU - $COLLAB_USER -c "$COLLAB_SCRIPT stop" >> $COLLAB_LOG 2>&1` 138 | sleep 2 139 | 140 | #if it's still running, the script "stop" must not have worked 141 | if checkpid $kpid 2>&1; 142 | then 143 | `kill $kpid > /dev/null 2>&1` 144 | sleep 2 145 | fi 146 | 147 | #if it's still running, then just fail 148 | if checkpid $kpid 2>&1; 149 | then 150 | failure 151 | echo 152 | else 153 | rm -f $PID_FILE 154 | rm -f /var/lock/subsys/collabreate 155 | success 156 | echo 157 | fi 158 | else 159 | failure $"Stopping collabreate server" 160 | #echo -e "\n"A 161 | #this basically assumes that collabreate is the only java process running as USER 162 | apid=$(pgrep -u $COLLAB_USER java) 163 | if checkpid $apid 2>&1; 164 | then 165 | echo " The server may have been started without using this init script!" 166 | echo " Sever appears already be running: pid $apid" 167 | echo " Use the management application to shutdown the server" 168 | else 169 | echo " Server appears to not be running" 170 | fi 171 | echo 172 | fi 173 | return 0 174 | } 175 | 176 | case "$1" in 177 | start) 178 | start 179 | ;; 180 | stop) 181 | stop 182 | ;; 183 | status) 184 | #relies upon a few things, like the location of the pid file 185 | if status collabreate; 186 | then 187 | echo "" 188 | else 189 | #look for other pids, just in case 190 | #can't use pidofproc becuase it matches other java services 191 | apid=$(ps ax | grep "$COLLAB_SERVER_JAR" |grep -v grep | cut -d" " -f1) 192 | if checkpid $apid 2>&1; 193 | then 194 | echo " The server may have been started without using this init script!" 195 | echo " Possible pids: $apid " 196 | fi 197 | fi 198 | ;; 199 | restart) 200 | stop 201 | start 202 | ;; 203 | *) 204 | echo "Usage: $0 {start|stop|status|restart}" 205 | exit 1 206 | ;; 207 | esac 208 | exit $? 209 | 210 | 211 | -------------------------------------------------------------------------------- /server/java/collabreate/server/dbUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate Utils 3 | Copyright (C) 2008 Chris Eagle 4 | Copyright (C) 2008 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | package collabreate.server; 22 | 23 | import java.io.*; 24 | import java.net.*; 25 | import java.sql.*; 26 | import java.util.*; 27 | import com.google.gson.*; 28 | 29 | /** 30 | * dbUtils 31 | * This class offers various utility functions used by the servlet 32 | * @author Tim Vidas 33 | * @author Chris Eagle 34 | * @version 0.1.0, August 2008 35 | */ 36 | 37 | public class dbUtils implements CollabreateConstants { 38 | 39 | /** 40 | * getJDBCConnection sets up and returns a JDBC connection 41 | * @return a JDBC connection 42 | */ 43 | protected static Connection getJDBCConnection(ServerManager sm) { 44 | Connection con = null; 45 | JsonObject config = sm.getConfig(); 46 | String driver = getConfigString(config, "JDBC_DRIVER", "org.postgresql.Driver"); 47 | try { 48 | Class.forName(driver); 49 | if (driver.indexOf("mysql") != -1) { 50 | sm.setuseMysql(true); 51 | } 52 | } catch (java.lang.ClassNotFoundException e) { 53 | System.err.println("ClassNotFoundException: " + e.getMessage()); 54 | System.err.println("you need the jdbc jar for " + driver + " in your classpath!\n"); 55 | System.err.println("Current classpath is: "); 56 | System.err.println(System.getProperty("java.class.path")); 57 | e.printStackTrace(); 58 | return null; 59 | } 60 | 61 | try { 62 | String userid = getConfigString(config, "DB_USER", "collabreate"); 63 | String password = getConfigString(config, "DB_PASS", null); 64 | if (password == null) { 65 | //need to prompt for the password 66 | } 67 | String url = getConfigString(config, "JDBC_URL", null); 68 | if (url == null) { 69 | String dbname = getConfigString(config, "DB_NAME", "collabreate"); 70 | String host = getConfigString(config, "DB_HOST", "127.0.0.1"); 71 | String ssl = getConfigString(config, "USE_SSL", "no"); 72 | String dbtype = getConfigString(config, "JDBC_NAME", "postgresql"); 73 | url = "jdbc:" + dbtype + "://" + host + "/" + dbname; 74 | if (ssl.equalsIgnoreCase("yes")) { 75 | url += "?ssl"; 76 | } 77 | } 78 | con = DriverManager.getConnection(url, userid, password); 79 | } catch(SQLException ex) { 80 | System.err.println("SQLException: " + ex.getMessage()); 81 | System.err.println("check permissions in your database configuration file\n"); 82 | return null; 83 | } 84 | try { 85 | DatabaseMetaData meta = con.getMetaData(); 86 | System.out.println("Connected to " + meta.getURL()); 87 | System.out.print("DB Driver : " + meta.getDriverName()); 88 | System.out.println(" v: " + meta.getDriverVersion()); 89 | System.out.println("Database: " + meta.getDatabaseProductName() + " " 90 | + meta.getDatabaseMajorVersion() + "." + meta.getDatabaseMinorVersion()); 91 | System.out.println("JDBC v: " + meta.getJDBCMajorVersion() + "." + meta.getJDBCMinorVersion()); 92 | } catch(Exception ex1) { 93 | System.err.println("Couldn't get driver metadata: " + ex1.getMessage()); 94 | //Is this a fatal error, do you want to close con here? 95 | } 96 | return con; 97 | } 98 | 99 | private static String getConfigString(JsonObject config, String key, String default_value) { 100 | if (config.has(key)) { 101 | return config.getAsJsonPrimitive(key).getAsString(); 102 | } 103 | return default_value; 104 | } 105 | 106 | private static int getConfigInt(JsonObject config, String key, int default_value) { 107 | if (config.has(key)) { 108 | return config.getAsJsonPrimitive(key).getAsInt(); 109 | } 110 | return default_value; 111 | } 112 | 113 | /** 114 | * runInsertInt is a database insert helper function, it runs an insert and returns 115 | * a Int value based on the result of the query - Statements must return a value to 116 | * be used with this function 117 | * @param s a prepared statement that provides a return value 118 | * @return integer return of the insert query 119 | */ 120 | protected static int runInsertInt(PreparedStatement s) { 121 | int rval = -1; 122 | try { 123 | ResultSet rs = s.executeQuery(); 124 | if (rs.next()) { 125 | rval = rs.getInt(1); 126 | //System.out.println("SQL Insert rval: " + rval); 127 | } 128 | rs.close(); 129 | } catch (SQLException e) { 130 | System.err.println("SQL Exception encountered"); 131 | System.err.println(e); 132 | } catch (Exception exc) { 133 | System.err.println("Database Insert error: " + exc.getMessage()); 134 | // exc.printStackTrace(); 135 | } 136 | return rval; 137 | } 138 | 139 | /** 140 | * runInsertLong is a database insert helper function, it runs an insert and returns 141 | * a Long value based on the result of the query - Statements must return a value to 142 | * be used with this function 143 | * @param s a prepared statement that provides a return value 144 | * @return long return of the insert query 145 | */ 146 | protected static long runInsertLong(PreparedStatement s) { 147 | long rval = -1; 148 | try { 149 | ResultSet rs = s.executeQuery(); 150 | if (rs.next()) { 151 | rval = rs.getLong(1); 152 | System.out.println("SQL Insert rval: " + rval); 153 | } 154 | rs.close(); 155 | } catch (SQLException e) { 156 | System.err.println("SQL Exception encountered"); 157 | System.err.println(e); 158 | } catch (Exception exc) { 159 | System.err.println("Database Insert error: " + exc.getMessage()); 160 | exc.printStackTrace(); 161 | } 162 | return rval; 163 | } 164 | 165 | } 166 | 167 | -------------------------------------------------------------------------------- /server/c++/cli_mgr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate cli_mgr.cpp 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "utils.h" 26 | #include "client.h" 27 | #include "proj_info.h" 28 | #include "cli_mgr.h" 29 | #include "projectmap.h" 30 | #include "clientset.h" 31 | #include "io.h" 32 | 33 | UserInfo::UserInfo(const char *uname, uint32_t _uid, uint64_t _pub, uint64_t _sub) : username(uname) { 34 | uid = _uid; 35 | pub = _pub; 36 | sub = _sub; 37 | } 38 | 39 | UserInfo::UserInfo() : username("invalid") { 40 | uid = INVALID_UID; 41 | pub = 0; 42 | sub = 0; 43 | } 44 | 45 | Packet::Packet(Client *src, const char *cmd, json_object *obj, uint64_t updateid) { 46 | c = src; 47 | this->cmd = cmd; 48 | this->obj = obj; 49 | uid = updateid; 50 | append_json_uint64_val(obj, "updateid", updateid); //is this really necessary? 51 | } 52 | 53 | /** 54 | * For use in Basic mode when a Global project ID is not needed 55 | */ 56 | const char * const ConnectionManager::EMPTY_GPID = "0000000000000000000000000000000000000000000000000000000000000000"; 57 | 58 | ConnectionManager::ConnectionManager(json_object *conf) { 59 | this->conf = conf; 60 | done = false; 61 | sem_init(&pidLock, 0, 1); 62 | sem_init(&queueSem, 0, 0); 63 | sem_init(&queueMutex, 0, 1); 64 | } 65 | 66 | const UserInfo &ConnectionManager::getUserInfo(uint32_t uid) { 67 | static UserInfo invalid; 68 | if (user_map.find(uid) == user_map.end()) { 69 | return invalid; 70 | } 71 | return user_map[uid]; 72 | } 73 | 74 | void ConnectionManager::start() { 75 | pthread_attr_t attr; 76 | pthread_attr_init(&attr); 77 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 78 | pthread_t tid; 79 | pthread_create(&tid, &attr, run, (void*)this); 80 | } 81 | 82 | static bool termClients(Client *c, void *user) { 83 | c->terminate(); 84 | return true; 85 | } 86 | 87 | /** 88 | * terminate terminates the connection manager 89 | * it terminates all clients connected to all projects 90 | */ 91 | void ConnectionManager::terminate() { 92 | log(LINFO, "ConnectionManager terminating\n"); 93 | done = true; 94 | projects.loopClients(termClients, NULL); 95 | if (conf != NULL) { 96 | json_object_put(conf); 97 | conf = NULL; 98 | } 99 | } 100 | 101 | /** 102 | * remove removes a client from a currently reflecting project 103 | * @param c the client to remove (from whatever project it is already connected to) 104 | */ 105 | void ConnectionManager::remove(Client *c) { 106 | // logln("Removing client from " + c->getGpid() + " chain", LINFO1); 107 | projects.removeClient(c); 108 | } 109 | 110 | static bool clientStats(Client *c, void *user) { 111 | string *s = (string*)user; 112 | *s += c->dumpStats(); 113 | return true; 114 | } 115 | 116 | /** 117 | * dumpStats dumps send / receive stats for each connected client 118 | */ 119 | string ConnectionManager::dumpStats() { 120 | string sb = ""; 121 | projects.loopClients(clientStats, &sb); 122 | if (sb.length() == 0) { 123 | sb = "Stats:\n - none - \n"; 124 | } 125 | else { 126 | sb = "Stats:\n" + sb; 127 | } 128 | return sb; 129 | } 130 | 131 | static bool dispatch(Client *c, void *user) { 132 | Packet *p = (Packet*)user; 133 | 134 | if (c != p->c) { //only send to other than originator 135 | //increment ref count on json object before sending 136 | //because writeJson will decrement it and we can't have the object 137 | //garbage collected until all clients have received it 138 | json_object_get(p->obj); 139 | c->post(p->cmd, p->obj); 140 | } 141 | else { 142 | //send updateid back to the originator 143 | json_object *obj = json_object_new_object(); 144 | append_json_uint64_val(obj, "updateid", p->uid); 145 | c->send_data(MSG_ACK_UPDATEID, obj); 146 | } 147 | 148 | return true; 149 | } 150 | 151 | /** 152 | * run perpetually waits to be notified that a new packet has been queued, then 153 | * sends this packet to other clients according to permissions and project subscription 154 | * this also sends the server created unique updateID back to the originator of the packet 155 | */ 156 | void *ConnectionManager::run(void *arg) { 157 | ConnectionManager *mgr = (ConnectionManager*)arg; 158 | while (!mgr->done) { 159 | sem_wait(&mgr->queueSem); 160 | sem_wait(&mgr->queueMutex); 161 | Packet *p = mgr->queue[0]; 162 | //*** does add/remove need to be synchronized on vectors? 163 | mgr->queue.erase(mgr->queue.begin()); 164 | sem_post(&mgr->queueMutex); 165 | //get the project associated with this notification 166 | mgr->projects.loopProject(p->c->getPid(), dispatch, p); 167 | json_object_put(p->obj); 168 | delete p; 169 | } 170 | return NULL; 171 | } 172 | 173 | static bool clientList(Client *c, void *user) { 174 | string *s = (string*)user; 175 | char buf[64]; 176 | int len; 177 | //logln(cnt + c.getPeerAddr() + ":" + c.getPort() + " (?|" + c.getPub() + ") (?|" + c.getSub() + ") ????"); 178 | snprintf(buf, sizeof(buf), "%-9d", c->getUid()); 179 | *s += buf; 180 | len = snprintf(buf, sizeof(buf), "%s:", c->getPeerAddr().c_str()); 181 | *s += buf; 182 | snprintf(buf, sizeof(buf), "%-*d", 30 - len, c->getPeerPort()); 183 | *s += buf; 184 | snprintf(buf, sizeof(buf), "0x%08x ", (uint32_t)c->getPub()); 185 | *s += buf; 186 | snprintf(buf, sizeof(buf), "0x%08x ", (uint32_t)c->getSub()); 187 | *s += buf; 188 | snprintf(buf, sizeof(buf), "%-5d ", c->getPid()); 189 | *s += buf; 190 | snprintf(buf, sizeof(buf), "%3d: %s \n", c->getUid(), c->getUser().c_str()); 191 | *s += buf; 192 | return true; 193 | } 194 | 195 | /** 196 | * listConnection displays the current connections to the collabREate connection manager 197 | */ 198 | string ConnectionManager::listConnections() { 199 | string sb = ""; 200 | projects.loopClients(clientList, &sb); 201 | if (sb.length() == 0) { 202 | sb = "Client Address:Port Pub(Effective) Sub(Effective) PID User\n - none - \n"; 203 | } 204 | else { 205 | sb = "Client Address:Port Pub(Effective) Sub(Effective) PID User\n" + sb; 206 | } 207 | return sb; 208 | } 209 | 210 | -------------------------------------------------------------------------------- /server/c++/server_mgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate server_mgr.h 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef __SERVER_MGR_H 22 | #define __SERVER_MGR_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "client.h" 32 | #include "utils.h" 33 | 34 | using namespace std; 35 | 36 | class Project; 37 | class ServerManager; 38 | 39 | typedef void (*MsgHandler)(json_object *obj, ServerManager *sm); 40 | 41 | /** 42 | * ServerManager 43 | * This class is responsible for routine server related operations 44 | * @author Tim Vidas 45 | * @author Chris Eagle 46 | * @version 0.4.0, August 2012 47 | */ 48 | 49 | class ServerManager { 50 | private: 51 | bool done; 52 | json_object *config; 53 | PGconn *dbConn; 54 | int port; 55 | string host; 56 | 57 | int sock; //socket fd 58 | string json_buffer; 59 | int json_fd; 60 | string import_owner; 61 | json_object *import_json; 62 | int mode; 63 | 64 | sem_t waiter; 65 | 66 | json_object *readJson(); 67 | 68 | vector plist; 69 | static map handlers; 70 | 71 | static void *reader(void *arg); 72 | 73 | static void mng_connections(json_object *obj, ServerManager *sm); 74 | static void mng_stats(json_object *obj, ServerManager *sm); 75 | static void mng_import_reply(json_object *obj, ServerManager *sm); 76 | static void mng_project_list(json_object *obj, ServerManager *sm); 77 | static void mng_export_updates(json_object *obj, ServerManager *sm); 78 | static void msg_error(json_object *obj, ServerManager *sm); 79 | 80 | public: 81 | ServerManager(json_object *p); 82 | 83 | private: 84 | 85 | /** 86 | * deleteProject deletes a local project 87 | * @param pid the local project id to delete 88 | */ 89 | void deleteProject(int pid); 90 | 91 | /** 92 | * addUsers adds a user to this server 93 | * @param username the username to add 94 | * @param password the password for the user (hashed) 95 | * @param pub the publish permission bitmask 96 | * @param sub the subscribe permission bitmask 97 | * @return the userid of the added user, -1 on error 98 | */ 99 | int addUser(string username, string password, uint64_t pub, uint64_t sub); 100 | 101 | /** 102 | * updateUser updates a user on this server 103 | * @param username the username to update 104 | * @param password the password for the user (hashed) 105 | * @param pub the publish permission bitmask 106 | * @param sub the subscribe permission bitmask 107 | * @param uid the userid of the record to apply the other values to 108 | * @return the userid of the added user, -1 on error 109 | */ 110 | int updateUser(string username, string password, uint64_t pub, uint64_t sub, int uid); 111 | 112 | /** 113 | * terminate terminates the server manager 114 | */ 115 | void terminate(); 116 | 117 | /** 118 | * connectToHelper connects to the managerHelper on the server on MANAGE_PORT, 119 | * by default this must be a local connection. 120 | */ 121 | void connectToHelper(); 122 | 123 | void initQueries(); 124 | 125 | /** 126 | * similar to post in Client, but does not check subscription status, and takes command as a arg 127 | * This function should ONLY be called for message id >= MNG_CONTROL_FIRST 128 | * because these messages do not contain an updateid and send only management data 129 | * @param command the command to send 130 | * @param data the data associated with the command 131 | */ 132 | void send_data(const char *command, json_object *obj = NULL); 133 | 134 | /** 135 | * dumpStats dumps rx/tx stats for this server 136 | * this requires ServerHelper to be running 137 | */ 138 | 139 | void dumpStats(); 140 | 141 | /** 142 | * shutdownServer sends a request to the server to shutdown the server nicely 143 | * this requires ServerHelper to be running 144 | */ 145 | 146 | void shutdownServer(); 147 | 148 | /** 149 | * getProject gets project information for a previously listed project 150 | * @param lpid the local PID for the project to get info on 151 | * @param pinfo a project info object to populate with information 152 | * @return 0 on success 153 | */ 154 | int getProject(uint32_t lpid, Project *pinfo); 155 | 156 | /** 157 | * exportProject exports a project to a binary final 158 | * @param lpid the local PID for the project to export 159 | * @param efile the filename to export to 160 | * @return 0 on success 161 | */ 162 | int exportDatabaseProject(uint32_t lpid); 163 | int exportBasicProject(uint32_t lpid); 164 | 165 | int createDatabaseProject(const string &gpid, const string &hash, 166 | const string &desc, uint64_t pub, uint64_t sub); 167 | int importDatabaseProject(); 168 | int importBasicProject(); 169 | 170 | /** 171 | * importProject imports a project from a binary final 172 | * @param ifile the file descriptor to import from 173 | * @param newowner the local uid to be the owner of the new project 174 | */ 175 | int importProject(int ifile, const char *newowner); 176 | 177 | /** 178 | * getconfig is an inspector that gets the current operation mode of the connection manager 179 | * @return a Properites object 180 | */ 181 | json_object *getConfig(); 182 | 183 | /** 184 | * getMode is an inspector that gets the current operation mode of the connection manager 185 | * @return the mode 186 | */ 187 | int getMode(); 188 | 189 | /** 190 | * listConnections lists the current connections to this server 191 | * this requires ServerHelper to be running 192 | */ 193 | void listConnections(); 194 | 195 | /** 196 | * listUsers lists the users on this server 197 | */ 198 | void listUsers(); 199 | 200 | void listProjects(); 201 | 202 | /** 203 | * listProjects lists the projects on this server 204 | */ 205 | void listDatabaseProjects(); 206 | 207 | /** 208 | * listProjects lists the projects on this server 209 | */ 210 | void listBasicProjects(); 211 | 212 | /** 213 | * closeDB closes all the database queries and the database connection 214 | */ 215 | void closeDB(); 216 | 217 | string getPermHeaderString(size_t colWidth); 218 | 219 | string getPermHeaderString(size_t colWidth, bool number); 220 | 221 | string getPermRowString(uint64_t p, uint64_t s, size_t colWidth); 222 | 223 | public: 224 | /** 225 | * exec provides the cli interface for managing collabreate 226 | */ 227 | static void exec(int argc, char **argv); 228 | }; 229 | 230 | #endif 231 | -------------------------------------------------------------------------------- /json-c/json_tokener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $ 3 | * 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 | * Michael Clark 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | */ 11 | 12 | /** 13 | * @file 14 | * @brief Methods to parse an input string into a tree of json_object objects. 15 | */ 16 | #ifndef _json_tokener_h_ 17 | #define _json_tokener_h_ 18 | 19 | #include 20 | #include "json_object.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | enum json_tokener_error { 27 | json_tokener_success, 28 | json_tokener_continue, 29 | json_tokener_error_depth, 30 | json_tokener_error_parse_eof, 31 | json_tokener_error_parse_unexpected, 32 | json_tokener_error_parse_null, 33 | json_tokener_error_parse_boolean, 34 | json_tokener_error_parse_number, 35 | json_tokener_error_parse_array, 36 | json_tokener_error_parse_object_key_name, 37 | json_tokener_error_parse_object_key_sep, 38 | json_tokener_error_parse_object_value_sep, 39 | json_tokener_error_parse_string, 40 | json_tokener_error_parse_comment, 41 | json_tokener_error_size 42 | }; 43 | 44 | enum json_tokener_state { 45 | json_tokener_state_eatws, 46 | json_tokener_state_start, 47 | json_tokener_state_finish, 48 | json_tokener_state_null, 49 | json_tokener_state_comment_start, 50 | json_tokener_state_comment, 51 | json_tokener_state_comment_eol, 52 | json_tokener_state_comment_end, 53 | json_tokener_state_string, 54 | json_tokener_state_string_escape, 55 | json_tokener_state_escape_unicode, 56 | json_tokener_state_boolean, 57 | json_tokener_state_number, 58 | json_tokener_state_array, 59 | json_tokener_state_array_add, 60 | json_tokener_state_array_sep, 61 | json_tokener_state_object_field_start, 62 | json_tokener_state_object_field, 63 | json_tokener_state_object_field_end, 64 | json_tokener_state_object_value, 65 | json_tokener_state_object_value_add, 66 | json_tokener_state_object_sep, 67 | json_tokener_state_array_after_sep, 68 | json_tokener_state_object_field_start_after_sep, 69 | json_tokener_state_inf 70 | }; 71 | 72 | struct json_tokener_srec 73 | { 74 | enum json_tokener_state state, saved_state; 75 | struct json_object *obj; 76 | struct json_object *current; 77 | char *obj_field_name; 78 | }; 79 | 80 | #define JSON_TOKENER_DEFAULT_DEPTH 32 81 | 82 | struct json_tokener 83 | { 84 | char *str; 85 | struct printbuf *pb; 86 | int max_depth, depth, is_double, st_pos, char_offset; 87 | enum json_tokener_error err; 88 | unsigned int ucs_char; 89 | char quote_char; 90 | struct json_tokener_srec *stack; 91 | int flags; 92 | }; 93 | /** 94 | * @deprecated Unused in json-c code 95 | */ 96 | typedef struct json_tokener json_tokener; 97 | 98 | /** 99 | * Be strict when parsing JSON input. Use caution with 100 | * this flag as what is considered valid may become more 101 | * restrictive from one release to the next, causing your 102 | * code to fail on previously working input. 103 | * 104 | * This flag is not set by default. 105 | * 106 | * @see json_tokener_set_flags() 107 | */ 108 | #define JSON_TOKENER_STRICT 0x01 109 | 110 | /** 111 | * Given an error previously returned by json_tokener_get_error(), 112 | * return a human readable description of the error. 113 | * 114 | * @return a generic error message is returned if an invalid error value is provided. 115 | */ 116 | const char *json_tokener_error_desc(enum json_tokener_error jerr); 117 | 118 | /** 119 | * Retrieve the error caused by the last call to json_tokener_parse_ex(), 120 | * or json_tokener_success if there is no error. 121 | * 122 | * When parsing a JSON string in pieces, if the tokener is in the middle 123 | * of parsing this will return json_tokener_continue. 124 | * 125 | * See also json_tokener_error_desc(). 126 | */ 127 | JSON_EXPORT enum json_tokener_error json_tokener_get_error(struct json_tokener *tok); 128 | 129 | JSON_EXPORT struct json_tokener* json_tokener_new(void); 130 | JSON_EXPORT struct json_tokener* json_tokener_new_ex(int depth); 131 | JSON_EXPORT void json_tokener_free(struct json_tokener *tok); 132 | JSON_EXPORT void json_tokener_reset(struct json_tokener *tok); 133 | JSON_EXPORT struct json_object* json_tokener_parse(const char *str); 134 | JSON_EXPORT struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error); 135 | 136 | /** 137 | * Set flags that control how parsing will be done. 138 | */ 139 | JSON_EXPORT void json_tokener_set_flags(struct json_tokener *tok, int flags); 140 | 141 | /** 142 | * Parse a string and return a non-NULL json_object if a valid JSON value 143 | * is found. The string does not need to be a JSON object or array; 144 | * it can also be a string, number or boolean value. 145 | * 146 | * A partial JSON string can be parsed. If the parsing is incomplete, 147 | * NULL will be returned and json_tokener_get_error() will return 148 | * json_tokener_continue. 149 | * json_tokener_parse_ex() can then be called with additional bytes in str 150 | * to continue the parsing. 151 | * 152 | * If json_tokener_parse_ex() returns NULL and the error is anything other than 153 | * json_tokener_continue, a fatal error has occurred and parsing must be 154 | * halted. Then, the tok object must not be reused until json_tokener_reset() is 155 | * called. 156 | * 157 | * When a valid JSON value is parsed, a non-NULL json_object will be 158 | * returned. Also, json_tokener_get_error() will return json_tokener_success. 159 | * Be sure to check the type with json_object_is_type() or 160 | * json_object_get_type() before using the object. 161 | * 162 | * @b XXX this shouldn't use internal fields: 163 | * Trailing characters after the parsed value do not automatically cause an 164 | * error. It is up to the caller to decide whether to treat this as an 165 | * error or to handle the additional characters, perhaps by parsing another 166 | * json value starting from that point. 167 | * 168 | * Extra characters can be detected by comparing the tok->char_offset against 169 | * the length of the last len parameter passed in. 170 | * 171 | * The tokener does \b not maintain an internal buffer so the caller is 172 | * responsible for calling json_tokener_parse_ex with an appropriate str 173 | * parameter starting with the extra characters. 174 | * 175 | * This interface is presently not 64-bit clean due to the int len argument 176 | * so the function limits the maximum string size to INT32_MAX (2GB). 177 | * If the function is called with len == -1 then strlen is called to check 178 | * the string length is less than INT32_MAX (2GB) 179 | * 180 | * Example: 181 | * @code 182 | json_object *jobj = NULL; 183 | const char *mystring = NULL; 184 | int stringlen = 0; 185 | enum json_tokener_error jerr; 186 | do { 187 | mystring = ... // get JSON string, e.g. read from file, etc... 188 | stringlen = strlen(mystring); 189 | jobj = json_tokener_parse_ex(tok, mystring, stringlen); 190 | } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 191 | if (jerr != json_tokener_success) 192 | { 193 | fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 194 | // Handle errors, as appropriate for your application. 195 | } 196 | if (tok->char_offset < stringlen) // XXX shouldn't access internal fields 197 | { 198 | // Handle extra characters after parsed object as desired. 199 | // e.g. issue an error, parse another object from that point, etc... 200 | } 201 | // Success, use jobj here. 202 | 203 | @endcode 204 | * 205 | * @param tok a json_tokener previously allocated with json_tokener_new() 206 | * @param str an string with any valid JSON expression, or portion of. This does not need to be null terminated. 207 | * @param len the length of str 208 | */ 209 | JSON_EXPORT struct json_object* json_tokener_parse_ex(struct json_tokener *tok, 210 | const char *str, int len); 211 | 212 | #ifdef __cplusplus 213 | } 214 | #endif 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /json-c/json_object_iterator.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************* 3 | * @file json_object_iterator.h 4 | * 5 | * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P. 6 | * 7 | * This library is free software; you can redistribute it and/or modify 8 | * it under the terms of the MIT license. See COPYING for details. 9 | * 10 | * @brief An API for iterating over json_type_object objects, 11 | * styled to be familiar to C++ programmers. 12 | * Unlike json_object_object_foreach() and 13 | * json_object_object_foreachC(), this avoids the need to expose 14 | * json-c internals like lh_entry. 15 | * 16 | * API attributes:
17 | * * Thread-safe: NO
18 | * * Reentrant: NO 19 | * 20 | ******************************************************************************* 21 | */ 22 | 23 | 24 | #ifndef JSON_OBJECT_ITERATOR_H 25 | #define JSON_OBJECT_ITERATOR_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * Forward declaration for the opaque iterator information. 35 | */ 36 | struct json_object_iter_info_; 37 | 38 | /** 39 | * The opaque iterator that references a name/value pair within 40 | * a JSON Object instance or the "end" iterator value. 41 | */ 42 | struct json_object_iterator { 43 | const void* opaque_; 44 | }; 45 | 46 | 47 | /** 48 | * forward declaration of json-c's JSON value instance structure 49 | */ 50 | struct json_object; 51 | 52 | 53 | /** 54 | * Initializes an iterator structure to a "default" value that 55 | * is convenient for initializing an iterator variable to a 56 | * default state (e.g., initialization list in a class' 57 | * constructor). 58 | * 59 | * @code 60 | * struct json_object_iterator iter = json_object_iter_init_default(); 61 | * MyClass() : iter_(json_object_iter_init_default()) 62 | * @endcode 63 | * 64 | * @note The initialized value doesn't reference any specific 65 | * pair, is considered an invalid iterator, and MUST NOT 66 | * be passed to any json-c API that expects a valid 67 | * iterator. 68 | * 69 | * @note User and internal code MUST NOT make any assumptions 70 | * about and dependencies on the value of the "default" 71 | * iterator value. 72 | * 73 | * @return json_object_iterator 74 | */ 75 | struct json_object_iterator 76 | json_object_iter_init_default(void); 77 | 78 | /** Retrieves an iterator to the first pair of the JSON Object. 79 | * 80 | * @warning Any modification of the underlying pair invalidates all 81 | * iterators to that pair. 82 | * 83 | * @param obj JSON Object instance (MUST be of type json_object) 84 | * 85 | * @return json_object_iterator If the JSON Object has at 86 | * least one pair, on return, the iterator refers 87 | * to the first pair. If the JSON Object doesn't 88 | * have any pairs, the returned iterator is 89 | * equivalent to the "end" iterator for the same 90 | * JSON Object instance. 91 | * 92 | * @code 93 | * struct json_object_iterator it; 94 | * struct json_object_iterator itEnd; 95 | * struct json_object* obj; 96 | * 97 | * obj = json_tokener_parse("{'first':'george', 'age':100}"); 98 | * it = json_object_iter_begin(obj); 99 | * itEnd = json_object_iter_end(obj); 100 | * 101 | * while (!json_object_iter_equal(&it, &itEnd)) { 102 | * printf("%s\n", 103 | * json_object_iter_peek_name(&it)); 104 | * json_object_iter_next(&it); 105 | * } 106 | * 107 | * @endcode 108 | */ 109 | struct json_object_iterator 110 | json_object_iter_begin(struct json_object* obj); 111 | 112 | /** Retrieves the iterator that represents the position beyond the 113 | * last pair of the given JSON Object instance. 114 | * 115 | * @warning Do NOT write code that assumes that the "end" 116 | * iterator value is NULL, even if it is so in a 117 | * particular instance of the implementation. 118 | * 119 | * @note The reason we do not (and MUST NOT) provide 120 | * "json_object_iter_is_end(json_object_iterator* iter)" 121 | * type of API is because it would limit the underlying 122 | * representation of name/value containment (or force us 123 | * to add additional, otherwise unnecessary, fields to 124 | * the iterator structure). The "end" iterator and the 125 | * equality test method, on the other hand, permit us to 126 | * cleanly abstract pretty much any reasonable underlying 127 | * representation without burdening the iterator 128 | * structure with unnecessary data. 129 | * 130 | * @note For performance reasons, memorize the "end" iterator prior 131 | * to any loop. 132 | * 133 | * @param obj JSON Object instance (MUST be of type json_object) 134 | * 135 | * @return json_object_iterator On return, the iterator refers 136 | * to the "end" of the Object instance's pairs 137 | * (i.e., NOT the last pair, but "beyond the last 138 | * pair" value) 139 | */ 140 | struct json_object_iterator 141 | json_object_iter_end(const struct json_object* obj); 142 | 143 | /** Returns an iterator to the next pair, if any 144 | * 145 | * @warning Any modification of the underlying pair 146 | * invalidates all iterators to that pair. 147 | * 148 | * @param iter [IN/OUT] Pointer to iterator that references a 149 | * name/value pair; MUST be a valid, non-end iterator. 150 | * WARNING: bad things will happen if invalid or "end" 151 | * iterator is passed. Upon return will contain the 152 | * reference to the next pair if there is one; if there 153 | * are no more pairs, will contain the "end" iterator 154 | * value, which may be compared against the return value 155 | * of json_object_iter_end() for the same JSON Object 156 | * instance. 157 | */ 158 | void 159 | json_object_iter_next(struct json_object_iterator* iter); 160 | 161 | 162 | /** Returns a const pointer to the name of the pair referenced 163 | * by the given iterator. 164 | * 165 | * @param iter pointer to iterator that references a name/value 166 | * pair; MUST be a valid, non-end iterator. 167 | * 168 | * @warning bad things will happen if an invalid or 169 | * "end" iterator is passed. 170 | * 171 | * @return const char* Pointer to the name of the referenced 172 | * name/value pair. The name memory belongs to the 173 | * name/value pair, will be freed when the pair is 174 | * deleted or modified, and MUST NOT be modified or 175 | * freed by the user. 176 | */ 177 | const char* 178 | json_object_iter_peek_name(const struct json_object_iterator* iter); 179 | 180 | 181 | /** Returns a pointer to the json-c instance representing the 182 | * value of the referenced name/value pair, without altering 183 | * the instance's reference count. 184 | * 185 | * @param iter pointer to iterator that references a name/value 186 | * pair; MUST be a valid, non-end iterator. 187 | * 188 | * @warning bad things will happen if invalid or 189 | * "end" iterator is passed. 190 | * 191 | * @return struct json_object* Pointer to the json-c value 192 | * instance of the referenced name/value pair; the 193 | * value's reference count is not changed by this 194 | * function: if you plan to hold on to this json-c node, 195 | * take a look at json_object_get() and 196 | * json_object_put(). IMPORTANT: json-c API represents 197 | * the JSON Null value as a NULL json_object instance 198 | * pointer. 199 | */ 200 | struct json_object* 201 | json_object_iter_peek_value(const struct json_object_iterator* iter); 202 | 203 | 204 | /** Tests two iterators for equality. Typically used to test 205 | * for end of iteration by comparing an iterator to the 206 | * corresponding "end" iterator (that was derived from the same 207 | * JSON Object instance). 208 | * 209 | * @note The reason we do not (and MUST NOT) provide 210 | * "json_object_iter_is_end(json_object_iterator* iter)" 211 | * type of API is because it would limit the underlying 212 | * representation of name/value containment (or force us 213 | * to add additional, otherwise unnecessary, fields to 214 | * the iterator structure). The equality test method, on 215 | * the other hand, permits us to cleanly abstract pretty 216 | * much any reasonable underlying representation. 217 | * 218 | * @param iter1 Pointer to first valid, non-NULL iterator 219 | * @param iter2 POinter to second valid, non-NULL iterator 220 | * 221 | * @warning if a NULL iterator pointer or an uninitialized 222 | * or invalid iterator, or iterators derived from 223 | * different JSON Object instances are passed, bad things 224 | * will happen! 225 | * 226 | * @return json_bool non-zero if iterators are equal (i.e., both 227 | * reference the same name/value pair or are both at 228 | * "end"); zero if they are not equal. 229 | */ 230 | json_bool 231 | json_object_iter_equal(const struct json_object_iterator* iter1, 232 | const struct json_object_iterator* iter2); 233 | 234 | 235 | #ifdef __cplusplus 236 | } 237 | #endif 238 | 239 | 240 | #endif /* JSON_OBJECT_ITERATOR_H */ 241 | -------------------------------------------------------------------------------- /server/c++/server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | collabREate server.cpp 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the Free 8 | Software Foundation; either version 2 of the License, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "utils.h" 42 | #include "basic_mgr.h" 43 | #include "db_mgr.h" 44 | #include "mgr_helper.h" 45 | #include "client.h" 46 | 47 | #define ERROR_NO_USER "Failed to find user %s" 48 | #define ERROR_NO_PRIVS "drop_privs failed!" 49 | #define ERROR_BAD_GID "setgid current gid: %d target gid: %d\n" 50 | #define ERROR_BAD_UID "setuid current uid: %d target uid: %d\n" 51 | #define ERROR_SET_SIGCHLD "Unable to set SIGCHLD handler" 52 | #define ERROR_SET_SIGTERM "Unable to set SIGTERM handler" 53 | 54 | json_object *conf = NULL; 55 | 56 | ManagerHelper *helper; 57 | 58 | /* 59 | * This farms exit status from forked children to avoid 60 | * having any zombie processes lying around 61 | */ 62 | void sigterm(int sig) { 63 | if (helper) { 64 | helper->shutdown(); 65 | } 66 | exit(0); 67 | } 68 | 69 | /* 70 | * This farms exit status from forked children to avoid 71 | * having any zombie processes lying around 72 | */ 73 | void sigchld(int sig) { 74 | int status; 75 | // while (waitpid(-1, &status, WNOHANG) > 0); 76 | while (wait4(-1, &status, WNOHANG, NULL) > 0) { 77 | // fprintf(stderr, "wait4 called\n"); 78 | } 79 | // fprintf(stderr, "sigchld returning\n"); 80 | } 81 | 82 | struct ClientArgs { 83 | ClientArgs(ConnectionManager *_cm, NetworkIO *_nio) : cm(_cm), nio(_nio) {}; 84 | ConnectionManager *cm; 85 | NetworkIO *nio; 86 | }; 87 | 88 | #define AUTH_TRIES 3 89 | 90 | //perform authentication on the new connection before instantiating and running a new Client 91 | void *client_func(void *arg) { 92 | if (arg) { 93 | ClientArgs *ca = (ClientArgs*)arg; 94 | for (int i = 0; i < AUTH_TRIES; i++) { 95 | json_object *response = json_object_new_object(); 96 | append_json_string_val(response, "type", MSG_AUTH_REPLY); 97 | 98 | uint32_t uid = ca->cm->doAuth(ca->nio); 99 | if (uid < FIRST_BAD_UID) { 100 | append_json_int32_val(response, "reply", AUTH_REPLY_SUCCESS); 101 | ca->nio->writeJson(response); 102 | Client *c = new Client(ca->cm, ca->nio, uid); 103 | delete ca; 104 | c->run(); 105 | delete c; 106 | break; 107 | } 108 | else { 109 | append_json_int32_val(response, "reply", AUTH_REPLY_FAIL); 110 | ca->nio->writeJson(response); 111 | } 112 | } 113 | } 114 | return NULL; 115 | } 116 | 117 | //create a new thread to handle the new connection 118 | void start_client(ConnectionManager *cm, NetworkIO *nio) { 119 | pthread_attr_t attr; 120 | pthread_attr_init(&attr); 121 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 122 | pthread_t tid; 123 | //handle the new client in a new thread 124 | pthread_create(&tid, &attr, client_func, new ClientArgs(cm, nio)); 125 | } 126 | 127 | /* 128 | * Enter a threaded accept loop. Create a new thread using the 129 | * client_callback function for each new client connection. If 130 | * the client thread crashes, the entire server crashes. 131 | */ 132 | void loop(NetworkService *svc) { 133 | ConnectionManager *mgr; 134 | if (conf == NULL) { 135 | mgr = new BasicConnectionManager(conf); 136 | } 137 | else { 138 | const char *mode = string_from_json(conf, "SERVER_MODE"); 139 | if (mode != NULL && strcmp(mode, "database") == 0) { 140 | fprintf(stderr, "Creating database mode manager\n"); 141 | mgr = new DatabaseConnectionManager(conf); 142 | } 143 | else { 144 | fprintf(stderr, "Creating basic mode manager\n"); 145 | mgr = new BasicConnectionManager(conf); 146 | } 147 | } 148 | //should choose between Basic and Database connection managers here 149 | mgr->start(); 150 | //need to instantiate a ManagerHelper here as well 151 | ManagerHelper hlp(mgr, conf); 152 | hlp.start(); 153 | helper = &hlp; 154 | while (!hlp.done) { 155 | NetworkIO *nio = svc->accept(); 156 | fprintf(stderr, "Accepted new client\n"); 157 | if (nio) { 158 | start_client(mgr, nio); 159 | } 160 | } 161 | while (!hlp.quit) {}; 162 | } 163 | 164 | /* 165 | * Do the real work of dropping privileges. Checks to 166 | * see what the current uid/gid are, sets res gid and 167 | * uid to the specified user's uid/gid and verifies 168 | * that privs can't be restored to the initial uid/gid 169 | */ 170 | int drop_privs(struct passwd *pw) { 171 | char *dir; 172 | uid_t uid = getuid(); 173 | gid_t gid = getgid(); 174 | #if defined DO_CHROOT 175 | dir = "/"; 176 | if (chroot(pw->pw_dir) == -1) {; 177 | #ifdef DEBUG 178 | perror("chroot"); 179 | fprintf(stderr, "Failed chroot to %s", pw->pw_dir); 180 | #endif 181 | return -1; 182 | } 183 | #else 184 | dir = pw->pw_dir; 185 | #endif 186 | initgroups(pw->pw_name, pw->pw_gid); 187 | if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0) return -1; 188 | if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0) return -1; 189 | if (pw->pw_gid != gid && (setgid(gid) != -1 || setegid(gid) != -1)) { 190 | #ifdef DEBUG 191 | printf(ERROR_BAD_GID, getgid(), pw->pw_gid); 192 | #endif 193 | return -1; 194 | } 195 | if (pw->pw_uid != uid && (setuid(uid) != -1 || seteuid(uid) != -1)) { 196 | #ifdef DEBUG 197 | printf(ERROR_BAD_UID, getuid(), pw->pw_uid); 198 | #endif 199 | return -1; 200 | } 201 | if (getgid() != pw->pw_gid || getegid() != pw->pw_gid) return -1; 202 | if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) return -1; 203 | 204 | if (chdir(dir) == -1) {; 205 | #ifdef DEBUG 206 | perror("chdir"); 207 | fprintf(stderr, "Failed chdir to %s", dir); 208 | #endif 209 | return -1; 210 | } 211 | return 0; 212 | } 213 | 214 | /* 215 | * Drop privileges to the specified user account 216 | */ 217 | int drop_privs_user(const char *user_name) { 218 | struct passwd *pw = getpwnam(user_name); 219 | if (pw == NULL) { 220 | #ifdef DEBUG 221 | err(-1, ERROR_NO_USER, user_name); 222 | #else 223 | exit(-1); 224 | #endif 225 | } 226 | if (drop_privs(pw) == -1) { 227 | #ifdef DEBUG 228 | err(-1, ERROR_NO_PRIVS); 229 | #else 230 | exit(-1); 231 | #endif 232 | } 233 | return 0; 234 | } 235 | 236 | void writePidFile() { 237 | string pidFile = getStringOption(conf, "PIDFILE", "/var/run/collab/collab.pid"); 238 | FILE *f = fopen(pidFile.c_str(), "w"); 239 | if (f == NULL) { 240 | //this is a problem 241 | } 242 | else { 243 | pid_t pid = getpid(); 244 | fprintf(f, "%d", pid); 245 | fclose(f); 246 | } 247 | } 248 | 249 | /* 250 | * main function creates a socket, drops privileges 251 | * then calls a function to accept incoming connections in a loop. 252 | */ 253 | int main(int argc, char **argv, char **envp) { 254 | const char *mode; 255 | Tcp6Service *svc; 256 | srand(time(NULL)); 257 | if (signal(SIGCHLD, sigchld) == SIG_ERR) { 258 | #ifdef DEBUG 259 | err(-1, ERROR_SET_SIGCHLD); 260 | #else 261 | exit(-1); 262 | #endif 263 | } 264 | if (signal(SIGTERM, sigterm) == SIG_ERR) { 265 | #ifdef DEBUG 266 | err(-1, ERROR_SET_SIGTERM); 267 | #else 268 | exit(-1); 269 | #endif 270 | } 271 | int opt; 272 | while ((opt = getopt(argc, argv, "c:")) != -1) { 273 | switch (opt) { 274 | case 'c': 275 | conf = parseConf(optarg); 276 | if (conf == NULL) { 277 | fprintf(stderr, "Failed to parse json config file: %s\n", optarg); 278 | } 279 | break; 280 | default: 281 | break; 282 | } 283 | } 284 | short svc_port = getShortOption(conf, "SERVER_PORT", 5042); 285 | string svc_host = getStringOption(conf, "SERVER_HOST", ""); 286 | const char *svc_user = getCstringOption(conf, "RUN_AS", NULL); 287 | try { 288 | if (svc_host.length() == 0) { 289 | svc = new Tcp6Service(svc_port); 290 | } 291 | else { 292 | svc = new Tcp6Service(svc_host.c_str(), svc_port); 293 | } 294 | } catch (int e) { 295 | exit(e); 296 | } 297 | if (svc_user != NULL) { 298 | drop_privs_user(svc_user); 299 | } 300 | 301 | mode = string_from_json(conf, "SERVER_MODE"); 302 | if (mode != NULL && strcmp(mode, "debug")) { 303 | daemon(1, 0); 304 | } 305 | writePidFile(); 306 | loop(svc); 307 | return 0; 308 | } 309 | 310 | -------------------------------------------------------------------------------- /server/java/collabreate/server/README: -------------------------------------------------------------------------------- 1 | /* 2 | IDA Pro Collabreation/Synchronization Plugin 3 | Copyright (C) 2008 Chris Eagle 4 | Copyright (C) 2008 Tim Vidas 5 | 6 | 7 | This program is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by the Free 9 | Software Foundation; either version 2 of the License, or (at your option) 10 | any later version. 11 | 12 | This program is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 | more details. 16 | 17 | You should have received a copy of the GNU General Public License along with 18 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 19 | Place, Suite 330, Boston, MA 02111-1307 USA 20 | 21 | */ 22 | 23 | Version 0.2.0 Initial release 24 | 25 | Note: This server component is also released as FC15 based virtual appliance. 26 | This Virtual Machine is largely a stock FC15 minimal install, with postgres/ 27 | postgres-server, openjdk-java-1.6.0 packages, and 28 | collabreate software already installed. 29 | See www.idabook.com/collabreate for more information. 30 | 31 | 32 | QUICKSTART GUIDE 33 | 34 | Of course you should read this entire file prior to using the collabreate server. 35 | For the other 90% of users, here is a 6 step process that attempts to get you 36 | started. 37 | 38 | 1) install postgres (or mysql) and configure permissions (eg pg_hba.conf) 39 | 2) #./init_database.sh 40 | 3) #make 41 | 4) #make test (to visually inspect) 42 | 5) #make install (optional) 43 | 44 | if you performed step 5 you can start the server by: 45 | 6) #/etc/init.d/collabreate start 46 | 47 | if you chose not to install you can run from the build directory via scripts: 48 | 6) #./launch_server.sh server.conf 49 | 50 | Add users using the manager interface. Connect to the server via the plugin. 51 | 52 | #./launch_manager.sh server.conf 53 | 54 | EDITING THE CONFIGURATION 55 | 56 | Several parameters are tunable, include database information, logging verbosity, 57 | the TCP port number, etc. These can be changed by editing server.conf 58 | 59 | At the very least you should skim this file to verify default settings. The 60 | default database type is PostgreSQL. 61 | 62 | 63 | BUILDING THE SERVER 64 | 65 | Building the collabreate server requires the java SDK (tested with 1.6). For 66 | full functionality you also need a JDBC connector for your database (PostgreSQL 67 | 9.0 http://jdbc.postgresql.org/download/postgresql-9.0-801.jdbc4.jar) 68 | 69 | Due to the structure of some queries, PostgreSQL 8.2 or higher is required. 70 | 71 | Unpack the archive: 72 | 73 | #tar -zxf collabreate.tgz 74 | 75 | The server subdirectory contains all the server components: 76 | 77 | Compile the required classes: 78 | 79 | #javac collabreate/server/*.java 80 | 81 | At this point you can try out the server: 82 | 83 | #java collabreate.server.CollabreateServer collabreate/server/server.conf 84 | 85 | 86 | EXECUTABLE JAR FILES 87 | 88 | Alternatively, cd into collabreate/server/ and use make: 89 | 90 | #make all 91 | 92 | At this point you can run the server via the launch_server.sh script 93 | 94 | #./launch_server.sh server.conf 95 | 96 | This launches the server in the background 97 | 98 | #make install 99 | 100 | This installs server files, control files, etc. To visually inspect the 101 | install process prior to install, run "make test". You can now start via 102 | init.d 103 | 104 | #/etc/init.d/collabreate start 105 | 106 | 107 | CUSTOMIZING VIA YOUR ENVIRONMENT (optional) 108 | 109 | While using the environmental variables is optional, specify JAVA_HOME is 110 | recommended. 111 | 112 | Several build and management items can be configure by exporting environmental 113 | variables. If these variables are not set, either the script will attempt to 114 | determine the correct setting or default values will be used. 115 | 116 | JAVA_HOME - home directory for java 117 | INSTALLDIR - where to install the server, full path 118 | MANDIR - full path to the location of man files 119 | INITDIR - path to init.d 120 | INITBIN - name of file to place in init.d 121 | COLLAB_USER - name of user account the server will run as 122 | COLLAB_GROUP- group account 123 | 124 | the provided management scripts also provide similar customization. If you 125 | modified paths at build/install, you may need to make modifications here. 126 | 127 | JAVA_HOME - home directory for java 128 | COLLAB_SERVER_DIR - directory the server was installed into 129 | COLLAB_LOG - file that the scripts will log to 130 | COLLAB_SCRIPT - full path to collabctl 131 | COLLAB_USER - user account for collabreate server 132 | COLLAB_GROUP = group account 133 | 134 | DATABASE SETUP 135 | 136 | For database functionality there are a few more steps: 137 | 138 | A database must be setup for use with collabreate. 139 | create a database user and a database (collabDB for example): 140 | postgres: 141 | # createuser -U postgres collab 142 | Shall the new role be a superuser? (y/n) y 143 | Shall the new role be allowed to create databases? (y/n) y 144 | Shall the new role be allowed to create more new roles? (y/n) n 145 | CREATE ROLE 146 | # createdb -U collab collabDB 147 | CREATE DATABASE 148 | 149 | A sample .sql file is provided to install the schema: 150 | # psql -U collab -d collabDB -f dbschema.sql 151 | 152 | mysql: 153 | The user account creation is part of the provided sql script 154 | # mysql < my_dbschema.sql 155 | 156 | Finally you need to either install the JDBC jar file where java can find it, or 157 | provide the jar in the classpath on the command line: 158 | 159 | (the following two lines should be executed as one line) 160 | #java -cp "postgresql-9.0-801.jdbc4.jar:." 161 | collabreate/server/CollabreateServer server.conf 162 | 163 | Alternatively, if you have built jars, you can use the launch_server.sh script. 164 | 165 | 166 | USING THE SERVER 167 | 168 | By default (via the example server.conf) the server logs to /var/log/collab. 169 | You may specify an alternate log file location via the LogFile setting in the 170 | server configuration file. 171 | 172 | 173 | INTERACTING WITH THE SERVER 174 | 175 | A ServerManager application is included that allows you to create and list users 176 | and projects from the local console. The ServerManager may be launched using 177 | the provided launch_manager.sh script: 178 | 179 | #./launch_manager.sh 180 | 181 | which uses the same server configuration file used for the server to determine 182 | appropriate database parameters. 183 | 184 | Once started, the manager provides a simple menu to the console. The 185 | implemented functions are fairly easy to grasp, and perform actions such as 186 | adding users, listing users, listing projects, etc. Listing and editing users 187 | and projects have no effect in BASIC mode. 188 | 189 | 190 | IMPORT/EXPORT 191 | 192 | The ServerManager allows for importing and exporting projects. Exported 193 | projects are stored in a binary file format, that contains all project 194 | information including updates. Currently, related projects (parent, child, 195 | snapshot, etc) and related users (owner, updaters, etc) are not imported. 196 | For this reason, when importing from a file a new owner must be selected from 197 | the current server. 198 | 199 | PROJECT DELETION 200 | 201 | Currently, project deletion does not 'cascade' in any way. Deleting a 202 | project simply deletes the project information and related updates - not 203 | snapshots, child/parent projects, etc. 204 | 205 | 206 | PERMISSIONS 207 | Permissions can be assigned to users and to projects, furthermore both users 208 | and projects each have a set of publish and subscribe permissions. 209 | 210 | For a user to receive an update, that subscribe permission for that type of 211 | update must be granted for both the user and the project. 212 | 213 | For a user that is connected to a project to make a particular update, the 214 | publish permission for that type of update must by granted for both the user 215 | and that project. 216 | 217 | Permissions are granted by setting bits in the permissions bitfield (long) 218 | here is a summary of that bitfeild (least significant is bit 0) 219 | 0 "Undefine" 220 | 1 "Make Code" 221 | 2 "Make Data" 222 | 3 "Segments" 223 | 4 "Renames" 224 | 5 "Functions" 225 | 6 "Byte Patch" 226 | 7 "Comments" 227 | 8 "Optypes" 228 | 9 "Enums" 229 | 10 "Structs" 230 | 11 "Flirt" 231 | 12 "Thunk" 232 | 13 "Xrefs" 233 | 14-63 "Reserved for future use" 234 | 235 | If a user has only "Change comment" and "Name Change" publish permissions 236 | (0x48), those are the only to operations the user can perform, even if the 237 | project allows all changes (0x1FFF) 238 | 239 | Similarly if a project only allows "Change comment", "Change Name", "Patch 240 | Byte", and "Create/Delete/Change Struct" permissions (0x268) these are all 241 | that ANY user can perform even if the user is allows to make all changes i 242 | (0x1FFF). 243 | 244 | EXCEPTION: the project owner (which defaults to the creator), always has all 245 | permissions. 246 | 247 | The default operation of the server is to allow all users and all projects 248 | to have full publish and subscribe permissions. 249 | 250 | Note: these permissions are applied at the collabREate server and are 251 | independant of the publish and subscribe requests applied by the plugin. 252 | This allows for creating complex publish and subscribe models to fit almost 253 | any scenario. 254 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | /* 2 | IDA Pro Collaboration/Synchronization Plugin 3 | Copyright (C) 2018 Chris Eagle 4 | Copyright (C) 2018 Tim Vidas 5 | 6 | 7 | This program is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by the Free 9 | Software Foundation; either version 2 of the License, or (at your option) 10 | any later version. 11 | 12 | This program is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 | more details. 16 | 17 | You should have received a copy of the GNU General Public License along with 18 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple 19 | Place, Suite 330, Boston, MA 02111-1307 USA 20 | 21 | */ 22 | 23 | Version 1.0.0 24 | 25 | BACKGROUND: 26 | 27 | IdaPro has an event notification mechanism that plugins may utilize to be 28 | notified of many different types of changes being made to a database. The 29 | primary idea behind CollabREate is to hook these change notifications and 30 | broadcast changes to a central database server that records each change 31 | and forwards the associated change parameters to other interested users 32 | working on the same binary file. The theory being that one user's changes 33 | will be applied to a second user's database effectively allowing multiple 34 | users to simultaneously edit and annotate their databases. 35 | 36 | Please not that no single master copy of a particular IDB is maintained 37 | anywhere. A central database that records all events generated by all 38 | registered users is the only record of changes. It is entirely possible 39 | that the state of two databases diverges if one user were to make 40 | modifications without publishing those modifications to the database server. 41 | 42 | A major difficulty in this approach arises from the manner in which Ida 43 | notifications are generated. Because of the manner in which the Ida auto 44 | analysis subsystem operates, what appears to be a single action to the user 45 | may in fact translated into many (tens, hundreds, or even thousands) 46 | individual notification messages which all get pushed to the database. This 47 | makes conflict resolution between users and events extremely difficult 48 | because it is virtually impossible to associate a specific notification 49 | message with a specific user action. In fact some notification messages may, 50 | at first glance seem entirely unrelated to the user action which resulted in 51 | the generation of those notifications. 52 | 53 | Another challenge that arises is to supress the generation of duplicate 54 | notifications when processing incoming notifications. The current version of 55 | CollabREate simply de-registers itself for notifications while applying any 56 | changes indicated by each incoming message. This seems to work well unless 57 | the incoming messages results in the generation of more than one additional 58 | notification in the receiving IDB. In such cases, it is extremely difficult 59 | to determine when the last notification associated with the application of 60 | a newly received message has be generated, and therefore difficult to 61 | determine exactly when to re-register for receipt of local notifications. 62 | This is suspected to be one of the primary causes of a CollabREate database 63 | getting flooded with notifications and associated IDBs diverging in state. 64 | In practice, this problem seems to arise from actions that generate large 65 | numbers of notifications such as undefining large blocks of code or data 66 | or patching large numbers of bytes. 67 | 68 | RELEASE NOTES version 1.0.0 69 | 70 | Removed all Qt dependeicies, changed to use IDA API user interface functions. 71 | Notification protocol completely changed from a binary protocol to a 72 | json based protocol. Server and database updated accordingly. 73 | Support for IDA versions 6.5 through 7.0, older version no longer supported. 74 | Binaries now land in bin directory 75 | 76 | RELEASE NOTES version 0.4.0 77 | 78 | Removed dependency on QtNetwork. Reworked asynchronous networking 79 | for IDA versions 5.5 and later to make use of the IDA SDK execute_sync 80 | function. Updated MSVC build files so that a single build file accomodates 81 | multiple versions of IDA. 82 | 83 | RELEASE NOTES version 0.3.0 84 | 85 | This version of the plugin is NOT compatible with older (< 0.3.0) collabreate 86 | databases. This is a result of the addtion of 64 bit support. If you need 87 | to use old databases, then you should continue to use version 0.2.0. We may 88 | publish an upgrade utility that will upgrade 0.2.0 databases to 0.3.0 databases. 89 | For the purposes of this discussion we are talking about the SQL database that 90 | stores all of the IDA update notifications. 91 | 92 | BUILDING THE PLUGIN 93 | 94 | The IDA Pro plugin requires the IDA Pro SDK, which is distributed along with 95 | Pro. You need the version of the SDK that matches the version of IDA with 96 | which you intend to use the plugin. 97 | 98 | First you clone the repo, you should do this within 99 | the SDK's "plugins" directory: 100 | 101 | cd /plugins 102 | git clone https://github.com/cseagle/collabREate.git 103 | 104 | BUILDING FOR WINDOWS 105 | 106 | Using Visual Studio 2013 or later, open collabrete.sln 107 | 108 | Based on your IDA version select and build the corresponding project 109 | 110 | IDA Version Project to build Output file 111 | <= 6.95 idaq Release / Win32 bin/collabreate.plw 112 | <= 6.95 idaq64 Release64 / Win32 bin/collabreate.p64 113 | >= 7.0 ida Release / x64 bin/collabreate.dll 114 | >= 7.0 ida64 Release64 / x64 bin/collabreate64.dll 115 | 116 | BUILDING FOR LINUX / OSX 117 | 118 | Use the supplied Makefile to build the plugin 119 | 120 | $ make 121 | 122 | You may need to adjust paths to your SDK an IDA install in the Makefile 123 | see IDA_SDK and IDAHOME in the Makefile. 124 | 125 | Compiled binairs should land in the bin directory. 126 | 127 | The plugin depends on the json-c library from github: 128 | https://github.com/json-c/json-c 129 | NOTE that the plugin uses features that are not available in the older 130 | versions of json-c that install with most package managers, so build 131 | and install from the github sources. 132 | 133 | 134 | INSTALLING THE PLUGIN 135 | 136 | As with any IDA plugin, simply copy the compiled plugin file into collabreate's 137 | bin directory to /plugins, where represents the location in 138 | which IDA is installed. 139 | 140 | Due to Windows' file locking, you will likely need to make sure all Ida databases 141 | are closed before copying to this directory. 142 | 143 | USING THE PLUGIN 144 | 145 | It is intended that a new collabreate session is used for each binary loaded 146 | into IDA Pro. Once a binary is loaded and the autoanalysis phase has completed 147 | you can activate CollabREate by via the hotkey ALT-F6 or the Edit/Plugins menu. 148 | 149 | Upon activation you will be presented with a series of dialogs prompting you to 150 | connect to a CollabREate server, authenticate, start a new project, etc. The 151 | exact series of steps will very upon the running mode of the server (such as if 152 | it is connected to a backend database or not). 153 | 154 | Typical Project Join Actions: 155 | Connect: Connects to a collabreate server (default port is 5042) 156 | Authenticate: Provide a User / Password to connect to the server 157 | Choose Project: Provides a list of 'related' projects (1) 158 | New Project: Request that the server creates a new project (2) 159 | Existing Project: Join an existing project 160 | Project Snapshot: Request a new project that is a Fork of an existing project 161 | at a particular, previously saved point (2) 162 | 163 | (1) only projects that match the MD5 of the binary loaded in IDA are displayed 164 | (2) when starting a new project you must provide a textual description 165 | 166 | When connecting to an existing project for the first time, you automatically 167 | recieve all updates that have been made to the project prior to you joining. 168 | On subsequent connections you will automatically receive any updates that have 169 | been made since the last time you were connected to the project. 170 | 171 | Once connected to a project, you can use IDA normally. Updates you make are 172 | sent to the server, updates other collabreators make are reflected in your 173 | database. 174 | 175 | 176 | Reactivating the plugin while the plugin is already activated will bring up a menu of 177 | collabreate specific commands. 178 | 179 | Collaboration Actions: 180 | Disconnect: Disconnect from the server. 181 | Fork: Immediatly fork the project with the updates that IDA has 182 | recieved and join this new project. (3) 183 | Snapshot: Save a snapshot (point in time) (3) 184 | Manage Req Perms: Allows the user to change the permissions requested when 185 | joining the project 186 | Manage Proj Perms: Allows the user (only if the user is the owner of the 187 | project) to alter the project permissions. 188 | 189 | (3) the user must provide a textual description 190 | 191 | Forking creates a new projet that can have further updates, and that others can 192 | participate in (join). Snapshots are simply 'projects at a point in time' - not 193 | actual projects. You can not 'join' a snapshot. You must fork a new project 194 | from a snapshot. Overall, snapshots take up much less space than forked 195 | projects. 196 | 197 | 198 | If the server is connected to a database backend, a unique project id is stored 199 | in the idb file and subsequent connections to a server will automatically 200 | connect to the correct project. 201 | --------------------------------------------------------------------------------