# HG changeset patch # User Olaf Wintermann # Date 1446318621 -3600 # Node ID 8a0a7754f123ec9477c93fdd6e140799b2b98a16 # Parent 2a394ccdd778249f959db8678a19494a9f87c138 experimental BSD support diff -r 2a394ccdd778 -r 8a0a7754f123 configure --- a/configure Sat Oct 31 18:02:07 2015 +0100 +++ b/configure Sat Oct 31 20:10:21 2015 +0100 @@ -72,6 +72,16 @@ PLATFORM=osx.mk fi +ISBSD=`echo $OS | grep -c BSD` +if [ $ISBSD = 1 ]; then + if `type clang > /dev/null`; then + CCONF=clang.mk + else + CCONF=gcc.mk + fi + PLATFORM=bsd.mk +fi + echo " include \$(BUILD_ROOT)/make/$CCONF include \$(BUILD_ROOT)/make/$PLATFORM diff -r 2a394ccdd778 -r 8a0a7754f123 make/bsd.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/bsd.mk Sat Oct 31 20:10:21 2015 +0100 @@ -0,0 +1,42 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + + +# compiler and linker flags +CFLAGS += -DBSD +LDFLAGS += -lpthread -lm -lldap + + +# platform dependend source files +PLATFORM_DAEMONOBJ = event_bsd.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .so +APP_EXT = + diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/daemon/acl.c --- a/src/server/daemon/acl.c Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/daemon/acl.c Sat Oct 31 20:10:21 2015 +0100 @@ -564,6 +564,18 @@ #endif +#ifdef BSD + +int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { + return 1; +} + +void fs_acl_finish() { + +} + +#endif + #ifdef LINUX diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/daemon/event_bsd.c --- a/src/server/daemon/event_bsd.c Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/daemon/event_bsd.c Sat Oct 31 20:10:21 2015 +0100 @@ -29,6 +29,8 @@ #include #include +#include "../util/atomic.h" + #include "event_bsd.h" event_handler_t* evhandler_create(int numthreads) { @@ -77,26 +79,65 @@ } void ev_handle_events(ev_thr_conf_t *conf) { + event_handler_t *ev = conf->handler; + int kq = conf->port; + free(conf); + + struct timespec timeout; + timeout.tv_nsec = 0; + timeout.tv_sec = 600; + + struct kevent events[16]; + + for(;;) { + // wait for events + int nev; + nev = kevent(kq, NULL, 0, events, 16, &timeout); + if(nev == -1) { + // TODO: check for error + perror("kevent"); + continue; + } + + for(int i=0;ifn) { + if(event->fn(ev, event)) { + // TODO: reassociate? + } else if(event->finish) { + event->finish(ev, event); + } + } + } + } } /* returns a event handler port */ int ev_get_port(event_handler_t *h) { + int nps = h->nports; + if(nps == 1) { + return h->ports[0]; + } + int cp = h->lp % nps; + ws_atomic_inc32(&h->lp); + + return h->ports[cp]; } int ev_pollin(event_handler_t *h, int fd, event_t *event) { - + struct kevent kev; + EV_SET(&kev, fd, EVFILT_READ, EV_ADD, 0, 0, event); + return kevent(ev_get_port(h), &kev, 1, NULL, 0, NULL); } int ev_pollout(event_handler_t *h, int fd, event_t *event) { - -} - -int ev_poll(event_handler_t *h, event_t *event) { - + struct kevent kev; + EV_SET(&kev, fd, EVFILT_WRITE, EV_ADD, 0, 0, event); + return kevent(ev_get_port(h), &kev, 1, NULL, 0, NULL); } int evt_send(event_handler_t *h, event_t *event) { - + return 0; } diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/daemon/event_bsd.h --- a/src/server/daemon/event_bsd.h Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/daemon/event_bsd.h Sat Oct 31 20:10:21 2015 +0100 @@ -54,8 +54,6 @@ int ev_get_port(event_handler_t *h); -int ev_poll(event_handler_t *h, event_t *event); - #ifdef __cplusplus } #endif diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/daemon/ldap_auth.c --- a/src/server/daemon/ldap_auth.c Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/daemon/ldap_auth.c Sat Oct 31 20:10:21 2015 +0100 @@ -71,7 +71,10 @@ LDAP* get_ldap_session(LDAPAuthDB *authdb) { LDAPConfig *config = &authdb->config; LDAP *ld = NULL; -#ifdef LINUX + +#ifdef SOLARIS + ld = ldap_init(config->hostname, config->port); +#else char *ldap_uri = NULL; asprintf(&ldap_uri, "ldap://%s:%d", config->hostname, config->port); int init_ret = ldap_initialize(&ld, ldap_uri); @@ -79,8 +82,6 @@ if(init_ret) { fprintf(stderr, "ldap_initialize failed\n"); } -#else - ld = ldap_init(config->hostname, config->port); #endif if(!ld) { return NULL; diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/public/nsapi.h --- a/src/server/public/nsapi.h Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/public/nsapi.h Sat Oct 31 20:10:21 2015 +0100 @@ -348,11 +348,13 @@ #ifdef XP_UNIX #include #include -#include /* new */ #include #ifndef HPUX #include #endif +#ifndef BSD +#include /* new */ +#endif #include #include #include diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/util/atomic.h --- a/src/server/util/atomic.h Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/util/atomic.h Sat Oct 31 20:10:21 2015 +0100 @@ -46,7 +46,11 @@ #define ws_atomic_inc32(intptr) OSAtomicIncrement32((volatile int32_t *)intptr) #define ws_atomic_dec32(intptr) OSAtomicDecrement32((volatile int32_t *)intptr) - +#elif defined(BSD) +#define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr, 1) +#define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr, 1) +#define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val) +#define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, va #else // use atomic.h #include diff -r 2a394ccdd778 -r 8a0a7754f123 src/server/util/util.c --- a/src/server/util/util.c Sat Oct 31 18:02:07 2015 +0100 +++ b/src/server/util/util.c Sat Oct 31 20:10:21 2015 +0100 @@ -428,7 +428,7 @@ { struct passwd *rv; -#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) +#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(BSD) errno = getpwnam_r(name, result, buffer, buflen, &rv); if (errno != 0) rv = NULL; @@ -447,7 +447,7 @@ { struct passwd *rv; -#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) +#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(BSD) errno = getpwuid_r(uid, result, buffer, buflen, &rv); if (errno != 0) rv = NULL;