diff --git a/Makefile.in b/Makefile.in index a5471bb4..813e1ed9 100755 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,5 @@ SRCS= \ audiodevices.c \ - audio_alsa.c \ - audio_msm_g1.c \ audio_reflector.c \ batman.c \ ciphers.c \ @@ -61,6 +59,12 @@ SRCS= \ vomp.c \ xprintf.c +# Only build these on Linux +ifeq (0, 1) +SRCS+= audio_alsa.c \ + audio_msm_g1.c +endif + MONITORCLIENTSRCS=conf.c \ log.c \ mkdir.c \ @@ -95,11 +99,14 @@ HDRS= fifo.h \ monitor-client.h \ sqlite-amalgamation-3070900/sqlite3.h -LDFLAGS=@LDFLAGS@ @PORTAUDIO_LIBS@ @SRC_LIBS@ @SPANDSP_LIBS@ @CODEC2_LIBS@ @PTHREAD_LIBS@ +LDFLAGS=@LDFLAGS@ @LIBS@ @PORTAUDIO_LIBS@ @SRC_LIBS@ @SPANDSP_LIBS@ @CODEC2_LIBS@ @PTHREAD_LIBS@ CFLAGS= -Isqlite-amalgamation-3070900 @CPPFLAGS@ @CFLAGS@ @PORTAUDIO_CFLAGS@ @SRC_CFLAGS@ @SPANDSP_CFLAGS@ @PTHREAD_CFLAGS@ $(VOIPTEST_CFLAGS) CFLAGS+=-fPIC CFLAGS+=-Wall -Wno-unused-value +# Solaris magic +CFLAGS+=-DSHA2_USE_INTTYPES_H -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1 + -include Makefile.dbg DEFS= @DEFS@ diff --git a/audiodevices.c b/audiodevices.c index bbab3d78..4373e901 100644 --- a/audiodevices.c +++ b/audiodevices.c @@ -30,8 +30,12 @@ int recordBufferSize=0; int detectAudioDevice() { +#ifdef ANDROID if (!audev) audev=audio_msm_g1_detect(); +#endif +#ifdef linux if (!audev) audev=audio_alsa_detect(); +#endif if (audev) { WHYF("Detected audio device '%s'",audev->name); return 0; diff --git a/batman.c b/batman.c index eb724632..f02b9f51 100644 --- a/batman.c +++ b/batman.c @@ -17,6 +17,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include +#include +#include #include #include "serval.h" @@ -206,9 +211,9 @@ int getBatmanPeerList(char *socket_path,struct in_addr peers[],int *peer_count,i askagain: /* Make socket */ - sock=socket(AF_LOCAL,SOCK_STREAM,0); + sock=socket(PF_UNIX,SOCK_STREAM,0); memset(&socket_address,0,sizeof(struct sockaddr_un)); - socket_address.sun_family=AF_LOCAL; + socket_address.sun_family=PF_UNIX; if (strlen(socket_path)>256) return WHY("BATMAN socket path too long"); strcpy(socket_address.sun_path,socket_path); diff --git a/client.c b/client.c index 2fa4a0f4..0b2aa78b 100644 --- a/client.c +++ b/client.c @@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include +#include #include "serval.h" int sock = -1; diff --git a/commandline.c b/commandline.c index bb455cf1..9e15df72 100644 --- a/commandline.c +++ b/commandline.c @@ -662,7 +662,9 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti creates a new server daemon process with the correct argv[0]. Otherwise, the servald process appears as a process with argv[0] = "org.servalproject". */ if (execpath) { - execl(execpath, execpath, "start", "foreground", NULL); + /* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't + * see it as a sentinal */ + execl(execpath, execpath, "start", "foreground", (void *)NULL); _exit(-1); } _exit(server(NULL)); @@ -672,10 +674,7 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti /* Main process. Allow a few seconds for the child process to report for duty. */ time_ms_t timeout = gettime_ms() + 5000; do { - struct timespec delay; - delay.tv_sec = 0; - delay.tv_nsec = 200000000; // 200 ms = 5 Hz - nanosleep(&delay, NULL); + sleep_ms(200); // 5 Hz } while ((pid = server_pid()) == 0 && gettime_ms() < timeout); if (pid == -1) return -1; diff --git a/config.guess b/config.guess index 0ded1579..4c54cb99 120000 --- a/config.guess +++ b/config.guess @@ -1 +1 @@ -/usr/share/libtool/config/config.guess \ No newline at end of file +/opt/csw/share/libtool/config/config.guess \ No newline at end of file diff --git a/config.sub b/config.sub index d50f0912..069b3dc6 120000 --- a/config.sub +++ b/config.sub @@ -1 +1 @@ -/usr/share/libtool/config/config.sub \ No newline at end of file +/opt/csw/share/libtool/config/config.sub \ No newline at end of file diff --git a/configure.in b/configure.in index f95d34e7..439c6b60 100644 --- a/configure.in +++ b/configure.in @@ -59,8 +59,15 @@ if test -n "$JAVAC"; then popdef([AC_MSG_ERROR]) fi +dnl XXX Isn't this pointless? we are always linked against libc AC_CHECK_LIB(c,srandomdev) +dnl Solaris hides nanosleep here +AC_CHECK_LIB(rt,nanosleep) + +dnl BSD way of getting socket creds +AC_CHECK_FUNC(getpeereid) + AC_CHECK_HEADERS( stdio.h \ errno.h \ @@ -86,6 +93,10 @@ AC_CHECK_HEADERS( signal.h \ jni.h \ alsa/asoundlib.h \ + ucred.h \ + sys/filio.h \ + sys/endian.h \ + sys/byteorder.h \ ) echo "Fetching and building NaCl if required." diff --git a/dna_helper.c b/dna_helper.c index d0559990..664523e3 100644 --- a/dna_helper.c +++ b/dna_helper.c @@ -179,7 +179,9 @@ dna_helper_start(const char *command, const char *arg, const char *mysid) fflush(stderr); _exit(-1); } - execl(command, command, arg, NULL); + /* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't + * see it as a sentinal */ + execl(command, command, arg, (void *)NULL); LOGF_perror(LOG_LEVEL_FATAL, "execl(%s, %s, %s, NULL)", command, command, arg ? arg : "NULL"); fflush(stderr); do { _exit(-1); } while (1); diff --git a/gateway.c b/gateway.c index b3b64f7b..8cf75f98 100644 --- a/gateway.c +++ b/gateway.c @@ -74,7 +74,9 @@ static int safeSystem(char *cmd_file) if(pid == -1) return WHY_perror("fork"); if (pid == 0) { - execlp(shell, shell, "-c", cmd_file,NULL); + /* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't + * see it as a sentinal */ + execlp(shell, shell, "-c", cmd_file,(void*)NULL); _exit(1); } // Wait for child to finish diff --git a/install-sh b/install-sh index 49e0f9f9..db4aa8c4 120000 --- a/install-sh +++ b/install-sh @@ -1 +1 @@ -/usr/share/libtool/config/install-sh \ No newline at end of file +/opt/csw/share/libtool/config/install-sh \ No newline at end of file diff --git a/keyring.c b/keyring.c index 95c3d189..d917deb6 100644 --- a/keyring.c +++ b/keyring.c @@ -1125,7 +1125,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid, int cn=0,in=0,kp=0; if (!keyring_find_sid(k,&cn,&in,&kp,sid)) { - RETURN(WHYNULL("Could not find SID in keyring, so can't find SAS")); + RETURNNULL(WHYNULL("Could not find SID in keyring, so can't find SAS")); } for(kp=0;kpcontexts[cn]->identities[in]->keypair_count;kp++) @@ -1139,7 +1139,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid, RETURN(k->contexts[cn]->identities[in]->keypairs[kp]->private_key); } - RETURN(WHYNULL("Identity lacks SAS")); + RETURNNULL(WHYNULL("Identity lacks SAS")); } struct sid_sas_mapping { @@ -1329,11 +1329,11 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid) ==KEYTYPE_CRYPTOBOX) bcopy(keyring->contexts[0]->identities[0]->keypairs[0]->public_key, mdp.out.src.sid,SID_SIZE); - else { RETURN(WHYNULL("couldn't request SAS (I don't know who I am)")); } + else { RETURNNULL(WHYNULL("couldn't request SAS (I don't know who I am)")); } mdp.out.payload_length=1; mdp.out.payload[0]=KEYTYPE_CRYPTOSIGN; if (overlay_mdp_dispatch(&mdp, 0 /* system generated */, NULL, 0)) - RETURN(WHYNULL("Failed to send SAS resolution request")); + RETURNNULL(WHYNULL("Failed to send SAS resolution request")); if (debug & DEBUG_KEYRING) DEBUGF("Dispatched SAS resolution request"); RETURN(NULL); @@ -1458,9 +1458,9 @@ struct nm_record nm_cache[NM_CACHE_SLOTS]; unsigned char *keyring_get_nm_bytes(sockaddr_mdp *known,sockaddr_mdp *unknown) { IN(); - if (!known) { RETURN(WHYNULL("known pub key is null")); } - if (!unknown) { RETURN(WHYNULL("unknown pub key is null")); } - if (!keyring) { RETURN(WHYNULL("keyring is null")); } + if (!known) { RETURNNULL(WHYNULL("known pub key is null")); } + if (!unknown) { RETURNNULL(WHYNULL("unknown pub key is null")); } + if (!keyring) { RETURNNULL(WHYNULL("keyring is null")); } int i; @@ -1478,7 +1478,7 @@ unsigned char *keyring_get_nm_bytes(sockaddr_mdp *known,sockaddr_mdp *unknown) in fact a known key */ int cn=0,in=0,kp=0; if (!keyring_find_sid(keyring,&cn,&in,&kp,known->sid)) - { RETURN(WHYNULL("known key is not in fact known.")); } + { RETURNNULL(WHYNULL("known key is not in fact known.")); } /* work out where to store it */ if (nm_slots_used #include #include +#include #include #ifdef __APPLE__ #include @@ -400,15 +401,15 @@ ssize_t get_self_executable_path(char *buf, size_t len) int log_backtrace(struct __sourceloc where) { open_logging(); - char execpath[160]; + char execpath[MAXPATHLEN]; if (get_self_executable_path(execpath, sizeof execpath) == -1) return WHY("cannot log backtrace: own executable path unknown"); - char tempfile[512]; - if (!FORM_SERVAL_INSTANCE_PATH(tempfile, "servalXXXXXX.gdb")) + char tempfile[MAXPATHLEN]; + if (!FORM_SERVAL_INSTANCE_PATH(tempfile, "servalgdb.XXXXX")) return -1; - int tmpfd = mkstemps(tempfile, 4); + int tmpfd = mkstemp(tempfile); if (tmpfd == -1) - return WHY_perror("mkstemps"); + return WHY_perror("mkstemp"); if (write_str(tmpfd, "backtrace\n") == -1) { close(tmpfd); unlink(tempfile); @@ -420,7 +421,7 @@ int log_backtrace(struct __sourceloc where) return -1; } char pidstr[12]; - snprintf(pidstr, sizeof pidstr, "%u", getpid()); + snprintf(pidstr, sizeof pidstr, "%jd", (intmax_t)getpid()); int stdout_fds[2]; if (pipe(stdout_fds) == -1) return WHY_perror("pipe"); @@ -442,7 +443,9 @@ int log_backtrace(struct __sourceloc where) _exit(-2); } close(stdout_fds[0]); - execlp("gdb", "gdb", "-n", "-batch", "-x", tempfile, execpath, pidstr, NULL); + /* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't + * see it as a sentinal */ + execlp("gdb", "gdb", "-n", "-batch", "-x", tempfile, execpath, pidstr, (void*)NULL); perror("execlp(\"gdb\")"); do { _exit(-3); } while (1); break; diff --git a/ltmain.sh b/ltmain.sh index 41599586..9cf62470 120000 --- a/ltmain.sh +++ b/ltmain.sh @@ -1 +1 @@ -/usr/share/libtool/config/ltmain.sh \ No newline at end of file +/opt/csw/share/libtool/config/ltmain.sh \ No newline at end of file diff --git a/monitor.c b/monitor.c index 3024b6c1..e9ecb17b 100644 --- a/monitor.c +++ b/monitor.c @@ -27,6 +27,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "rhizome.h" #include +#ifdef HAVE_UCRED_H +#include +#endif + #if defined(LOCAL_PEERCRED) && !defined(SO_PEERCRED) #define SO_PEERCRED LOCAL_PEERCRED #endif @@ -263,12 +267,14 @@ void monitor_client_poll(struct sched_ent *alarm) } static void monitor_new_client(int s) { -#ifdef linux +#ifdef SO_PEERCRED struct ucred ucred; socklen_t len; int res; -#else +#elif defined(HAVE_GETPEEREID) gid_t othergid; +#elif defined(HAVE_UCRED_H) + ucred_t *ucred; #endif uid_t otheruid; struct monitor_context *c; @@ -276,7 +282,8 @@ static void monitor_new_client(int s) { if (set_nonblock(s) == -1) goto error; -#ifdef linux +#ifdef SO_PEERCRED + /* Linux way */ len = sizeof(ucred); res = getsockopt(s, SOL_SOCKET, SO_PEERCRED, &ucred, &len); if (res) { @@ -288,11 +295,22 @@ static void monitor_new_client(int s) { goto error; } otheruid = ucred.uid; -#else +#elif defined(HAVE_UCRED_H) + /* Solaris way */ + if (getpeerucred(s, &ucred) != 0) { + WHY_perror("getpeerucred()"); + goto error; + } + otheruid = ucred_geteuid(ucred); + ucred_free(ucred); +#elif defined(HAVE_GETPEEREID) + /* BSD way */ if (getpeereid(s, &otheruid, &othergid) != 0) { WHY_perror("getpeereid()"); goto error; } +#else +#error No way to get socket peer credentials #endif if (otheruid != getuid()) { diff --git a/overlay_interface.c b/overlay_interface.c index 5895ef19..e41f2709 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include +#include #include #include #include "serval.h" @@ -219,7 +223,13 @@ int overlay_bind_socket(const struct sockaddr *addr, size_t addr_size, char *int /* Automatically close socket on calls to exec(). This makes life easier when we restart with an exec after receiving a bad signal. */ - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) | O_CLOEXEC); + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) | +#ifdef FD_CLOEXEC + FD_CLOEXEC +#else + O_CLOEXEC +#endif + ); #ifdef SO_BINDTODEVICE /* diff --git a/overlay_mdp.c b/overlay_mdp.c index e2997f73..f1e439a5 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -291,7 +291,7 @@ unsigned char *overlay_mdp_decrypt(overlay_frame *f, overlay_mdp_frame *mdp, int mdp->packetTypeAndFlags|=MDP_NOCRYPT|MDP_NOSIGN; break; case OF_CRYPTO_CIPHERED: - RETURN(WHYNULL("decryption not implemented")); + RETURNNULL(WHYNULL("decryption not implemented")); mdp->packetTypeAndFlags|=MDP_NOSIGN; break; case OF_CRYPTO_SIGNED: @@ -301,7 +301,7 @@ unsigned char *overlay_mdp_decrypt(overlay_frame *f, overlay_mdp_frame *mdp, int is not available. */ unsigned char *key = keyring_find_sas_public(keyring,mdp->out.src.sid); if (!key) - RETURN(WHYNULL("SAS key not currently on record, cannot verify")); + RETURNNULL(WHYNULL("SAS key not currently on record, cannot verify")); /* get payload and following compacted signature */ b=&f->payload->bytes[0]; diff --git a/overlay_payload.c b/overlay_payload.c index f14be10f..7405df9b 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -298,19 +298,24 @@ overlay_frame *op_dup(overlay_frame *in) /* clone the frame */ overlay_frame *out=malloc(sizeof(overlay_frame)); - if (!out) return WHYNULL("malloc() failed"); + if (!out) { + WHY("malloc() failed"); + return NULL; + } /* copy main data structure */ bcopy(in,out,sizeof(overlay_frame)); out->payload=ob_new(in->payload->length); if (!out->payload) { free(out); - return WHYNULL("ob_new() failed"); + WHY("ob_new() failed"); + return NULL; } if (ob_append_bytes(out->payload,&in->payload->bytes[0],in->payload->length)) { op_free(out); - return WHYNULL("could not duplicate payload bytes"); + WHY("could not duplicate payload bytes"); + return NULL; } return out; } diff --git a/peers.c b/peers.c index 7984f9b0..8bfaa6a1 100644 --- a/peers.c +++ b/peers.c @@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include +#include #include "serval.h" char *batman_socket=NULL; diff --git a/rhizome_database.c b/rhizome_database.c index e703ce54..5de71760 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -872,7 +872,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key) WARNF("File has grown by %lld bytes. I will just store the original number of bytes so that the hash (hopefully) matches",stat.st_size-m->fileLength); } - unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0); + unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_SHARED, fd, 0); if (addr==MAP_FAILED) { WHY_perror("mmap"); WHY("mmap() of associated file failed."); diff --git a/rhizome_http.c b/rhizome_http.c index 13393122..3270b324 100644 --- a/rhizome_http.c +++ b/rhizome_http.c @@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#ifdef HAVE_SYS_FILIO_H +#include +#endif #include "serval.h" #include "str.h" diff --git a/rhizome_packetformats.c b/rhizome_packetformats.c index 62a12110..7c2e61a4 100644 --- a/rhizome_packetformats.c +++ b/rhizome_packetformats.c @@ -21,6 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "rhizome.h" #include #include +#include +#include +#include +#include + int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar) { diff --git a/serval.h b/serval.h index 878cd6bc..f884da09 100644 --- a/serval.h +++ b/serval.h @@ -1163,5 +1163,6 @@ void dump_stack(); #define OUT() fd_func_exit(&_this_call); #define RETURN(X) { OUT() return(X); } +#define RETURNNULL { OUT() return(NULL); } #endif // __SERVALD_SERVALD_H diff --git a/serval_packetvisualise.c b/serval_packetvisualise.c index 5543f2da..40f231e2 100644 --- a/serval_packetvisualise.c +++ b/serval_packetvisualise.c @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include "xprintf.h" #define MAX_SPACES 120 diff --git a/server.c b/server.c index 23c8fef1..ec51105b 100644 --- a/server.c +++ b/server.c @@ -828,7 +828,13 @@ int createServerSocket() This makes life easier when we restart with an exec after receiving a bad signal. */ fcntl(sock, F_SETFL, - fcntl(sock, F_GETFL, NULL)|O_CLOEXEC); + fcntl(sock, F_GETFL, NULL)| +#ifdef FD_CLOEXEC + FD_CLOEXEC +#else + O_CLOEXEC +#endif + ); int i=1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i)); diff --git a/sha2.c b/sha2.c index 1761470d..f0fc9f07 100644 --- a/sha2.c +++ b/sha2.c @@ -36,8 +36,22 @@ #ifdef HAVE_SYS_ENDIAN_H #include #endif +#ifdef HAVE_SYS_BYTEORDER_H +#include +#endif #include "sha2.h" +/* Translate from Solaris */ +#ifndef BYTE_ORDER +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#ifdef _BIG_ENDIAN +#define BYTE_ORDER BIG_ENDIAN +#else +#define BYTE_ORDER LITTLE_ENDIAN +#endif +#endif + /* * ASSERT NOTE: * Some sanity checking code is included using assert(). On my FreeBSD