diff options
author | Rob Crittenden <rcritten@redhat.com> | 2005-02-23 18:19:13 +0000 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2005-02-23 18:19:13 +0000 |
commit | 21305115e547133a0122c44b7e9956ef78dc94be (patch) | |
tree | b72f28ba737b35c0f13003478f5e777146789ef3 /lib | |
parent | f64e827b9c3011b07b5d78dd52466236dc77346e (diff) | |
download | ds-21305115e547133a0122c44b7e9956ef78dc94be.tar.gz ds-21305115e547133a0122c44b7e9956ef78dc94be.tar.xz ds-21305115e547133a0122c44b7e9956ef78dc94be.zip |
149510
Strip down ACL code and support libraries to the bare minimum.
Diffstat (limited to 'lib')
32 files changed, 146 insertions, 6328 deletions
diff --git a/lib/base/Makefile b/lib/base/Makefile index d646be03..6676436a 100644 --- a/lib/base/Makefile +++ b/lib/base/Makefile @@ -38,62 +38,33 @@ $(OBJDEST): mkdir -p $(OBJDEST) ifeq ($(ARCH), WINNT) -OSOBJS = nterrors.o eventlog.o eventhandler.o ntpipe.o pathnames.o +OSOBJS = nterrors.o eventlog.o else OSOBJS = endif OBJS = $(addprefix $(OBJDEST)/, \ - dstats.o \ - daemon.o \ shexp.o \ - regexp.o \ - pblock.o \ plist.o \ - buffer.o \ - netbuf.o \ file.o \ - net.o \ - session.o \ - cinfo.o \ util.o \ - ereport.o \ - sem.o \ + net.o \ fsmutex.o \ systhr.o \ crit.o \ rwlock.o \ dns.o \ dnsdmain.o \ - shmem.o \ - dll.o \ - servssl.o \ lexer.o \ - restart.o \ - objndx.o \ - cache.o \ pool.o \ - time_cache.o \ - dns_cache.o \ system.o \ - xp.o \ nscperror.o \ - language.o \ - fasttime.o \ - secpwd.o \ + ereport.o \ $(OSOBJS) \ ) -MODULE_CFLAGS=-I$(BUILD_ROOT)/include/base - -ifeq ($(PRODUCT),"Netscape Catalog Server") -ifeq ($(ARCH), WINNT) -MCC_INCLUDE := $(subst -I$(BUILD_ROOT)/lib/libnet,,$(MCC_INCLUDE)) -endif -endif -#$(OBJDEST)/fasttime.o : $(OBJDIR)/fasttime.o -# cp $< $@ +MODULE_CFLAGS=-I$(BUILD_ROOT)/include/base -I$(BUILD_ROOT)/ldap/servers/slapd $(LIBS): $(OBJS) rm -f $@ diff --git a/lib/base/crit.cpp b/lib/base/crit.cpp index 06f5fba4..ceb9a634 100644 --- a/lib/base/crit.cpp +++ b/lib/base/crit.cpp @@ -18,7 +18,6 @@ #include "netsite.h" #include "crit.h" #include "pool.h" -#include "ereport.h" #include "base/dbtbase.h" @@ -29,13 +28,6 @@ */ #include "nspr.h" -/* private/primpl.h is gone fromnspr21 19971028 */ -#if 0 -#ifdef XP_WIN32 -#include "private/primpl.h" -#endif /* XP_WIN32 */ -#endif - #include "prthread.h" #include "prlock.h" #include "prcvar.h" @@ -97,12 +89,12 @@ NSAPI_PUBLIC void crit_enter(CRITICAL id) PRThread *me = PR_GetCurrentThread(); if ( crit->owner == me) { - NS_ASSERT(crit->count > 0); + PR_ASSERT(crit->count > 0); crit->count++; } else { PR_Lock(crit->lock); - NS_ASSERT(crit->count == 0); + PR_ASSERT(crit->count == 0); crit->count = 1; crit->owner = me; } @@ -121,7 +113,7 @@ NSAPI_PUBLIC void crit_exit(CRITICAL id) crit->owner = 0; PR_Unlock(crit->lock); } - NS_ASSERT(crit->count >= 0); + PR_ASSERT(crit->count >= 0); #endif } @@ -165,7 +157,7 @@ NSAPI_PUBLIC void condvar_wait(CONDVAR _cv) int saveCount = cv->lock->count; PRThread *saveOwner = cv->lock->owner; - NS_ASSERT(cv->lock->owner == PR_GetCurrentThread()); + PR_ASSERT(cv->lock->owner == PR_GetCurrentThread()); cv->lock->count = 0; cv->lock->owner = 0; @@ -185,7 +177,7 @@ NSAPI_PUBLIC void condvar_timed_wait(CONDVAR _cv, long secs) int saveCount = cv->lock->count; PRThread *saveOwner = cv->lock->owner; - NS_ASSERT(cv->lock->owner == PR_GetCurrentThread()); + PR_ASSERT(cv->lock->owner == PR_GetCurrentThread()); cv->lock->count = 0; cv->lock->owner = 0; @@ -205,7 +197,7 @@ NSAPI_PUBLIC void condvar_notify(CONDVAR _cv) { #ifdef USE_NSPR condvar_t *cv = (condvar_t *)_cv; - NS_ASSERT(cv->lock->owner == PR_GetCurrentThread()); + PR_ASSERT(cv->lock->owner == PR_GetCurrentThread()); PR_NotifyCondVar(cv->cvar); #endif } @@ -214,7 +206,7 @@ NSAPI_PUBLIC void condvar_notifyAll(CONDVAR _cv) { #ifdef USE_NSPR condvar_t *cv = (condvar_t *)_cv; - NS_ASSERT(cv->lock->owner == PR_GetCurrentThread()); + PR_ASSERT(cv->lock->owner == PR_GetCurrentThread()); PR_NotifyAllCondVar(cv->cvar); #endif } diff --git a/lib/base/dns.cpp b/lib/base/dns.cpp index f9e38886..3760cac5 100644 --- a/lib/base/dns.cpp +++ b/lib/base/dns.cpp @@ -17,8 +17,6 @@ #include "base/systems.h" #endif /* XP_WIN32 */ -#include "net.h" /* SYS_NETFD, various headers to do DNS */ - /* Under NT, these are taken care of by net.h including winsock.h */ #ifdef XP_UNIX #include <arpa/inet.h> /* inet_ntoa */ @@ -27,13 +25,8 @@ extern "C" int gethostname (char *name, size_t namelen); #endif #endif -#ifdef DNS_CACHE -#include "base/dns_cache.h" -#include "base/ereport.h" -#endif /* DNS_CACHE */ #include <stdio.h> #include <nspr.h> -#include "frame/conf.h" /* ---------------------------- dns_find_fqdn ----------------------------- */ @@ -75,9 +68,6 @@ char *dns_ip2host(char *ip, int verify) /* struct in_addr iaddr; */ PRNetAddr iaddr; char *hn; -#ifdef DNS_CACHE - dns_cache_entry_t *dns_entry; -#endif static unsigned long laddr = 0; static char myhostname[256]; PRHostEnt hent; @@ -90,23 +80,6 @@ char *dns_ip2host(char *ip, int verify) if((iaddr.inet.ip = inet_addr(ip)) == -1) goto bong; -#ifdef DNS_CACHE - if ( (dns_entry = dns_cache_lookup_ip((unsigned int)iaddr.inet.ip)) ) { - hn = NULL; - if ( dns_entry->host && - /* Only use entry if the cache entry has been verified or if - * verify is off... - */ - (dns_entry->verified || !verify) ) { - hn = STRDUP( dns_entry->host ); - (void)dns_cache_use_decrement(dns_entry); - return hn; - } - dns_cache_delete(dns_entry); - dns_entry = 0; - } -#endif - /* * See if it happens to be the localhost IP address, and try * the local host name if so. @@ -159,18 +132,7 @@ char *dns_ip2host(char *ip, int verify) goto bong; } -#ifdef DNS_CACHE - if ( (dns_entry = dns_cache_insert(hn, (unsigned int)iaddr.inet.ip, verify)) ) { - (void) dns_cache_use_decrement(dns_entry); - } -#endif /* DNS_CACHE */ return hn; bong: -#ifdef DNS_CACHE - /* Insert the lookup failure */ - if ( (dns_entry = dns_cache_insert(NULL, (unsigned int)iaddr.inet.ip, verify)) ) { - (void) dns_cache_use_decrement(dns_entry); - } -#endif /* DNS_CACHE */ return NULL; } diff --git a/lib/base/dnsdmain.cpp b/lib/base/dnsdmain.cpp index f37e475c..6972dcb5 100644 --- a/lib/base/dnsdmain.cpp +++ b/lib/base/dnsdmain.cpp @@ -10,7 +10,6 @@ #include "netsite.h" -#include "base/net.h" #include <string.h> #include <stdio.h> #ifdef XP_UNIX @@ -26,7 +25,6 @@ extern "C" { #include <nspr.h> } -#include "frame/conf.h" diff --git a/lib/base/ereport.cpp b/lib/base/ereport.cpp index 3454d01f..e7acad19 100644 --- a/lib/base/ereport.cpp +++ b/lib/base/ereport.cpp @@ -13,10 +13,9 @@ #include "private/pprio.h" /* for nspr20 binary release */ #include "netsite.h" #include "file.h" /* system_fopenWA, system_write_atomic */ -#include "pblock.h" -#include "session.h" #include "util.h" /* util_vsprintf */ #include "ereport.h" +#include "slapi-plugin.h" #include "base/dbtbase.h" @@ -25,217 +24,33 @@ #include <string.h> /* strcpy */ #include <time.h> /* localtime */ -#ifdef XP_UNIX -#include <syslog.h> /* error logging to syslog */ - -static SYS_FILE _error_fd; -#else /* WIN32 */ -#include <nt/regparms.h> -#include <nt/messages.h> -#include "eventlog.h" - -static SYS_FILE _error_fd; -#endif /* XP_UNIX */ - -static PRBool _ereport_initialized = PR_FALSE; - - -NSAPI_PUBLIC SYS_FILE ereport_getfd(void) { return _error_fd; } - - - -/* ----------------------------- ereport_init ----------------------------- */ - - -NSAPI_PUBLIC char *ereport_init(char *err_fn, char *email, - PASSWD pwuser, char *version) -{ - char err[MAGNUS_ERROR_LEN]; - SYS_FILE new_fd; - -#ifdef XP_UNIX - if(!strcmp(err_fn, "SYSLOG")) { -#ifdef NET_SSL - openlog("secure-httpd", LOG_PID, LOG_DAEMON); -#else - openlog("httpd", LOG_PID, LOG_DAEMON); -#endif - _error_fd = PR_ImportFile(ERRORS_TO_SYSLOG); - - _ereport_initialized = PR_TRUE; - return NULL; - } -#endif /* XP_UNIX */ - if( (new_fd = system_fopenWA(err_fn)) == SYS_ERROR_FD) { - util_snprintf(err, MAGNUS_ERROR_LEN, "can't open error log %s (%s)", err_fn, - system_errmsg()); -#ifdef XP_UNIX - _error_fd = PR_ImportFile(STDERR_FILENO); -#else - _error_fd = PR_ImportFile(NULL); -#endif - return STRDUP(err); - } - _error_fd = new_fd; - -#ifdef XP_UNIX - if(pwuser) - chown(err_fn, pwuser->pw_uid, pwuser->pw_gid); -#endif /* XP_UNIX */ - - _ereport_initialized = PR_TRUE; - - ereport(LOG_INFORM, XP_GetAdminStr(DBT_successfulServerStartup_)); - ereport(LOG_INFORM, XP_GetAdminStr(DBT_SBS_), MAGNUS_VERSION_STRING, BUILD_NUM); - if (strcasecmp(BUILD_NUM, version)) { - ereport(LOG_WARN, XP_GetAdminStr(DBT_netscapeExecutableAndSharedLibra_)); - ereport(LOG_WARN, XP_GetAdminStr(DBT_executableVersionIsS_), version); - ereport(LOG_WARN, XP_GetAdminStr(DBT_sharedLibraryVersionIsS_), BUILD_NUM); - - } - - /* Initialize thread-specific error handling */ - system_errmsg_init(); - - return NULL; -} - - - -/* -------------------------- ereport_terminate --------------------------- */ - - -NSAPI_PUBLIC void ereport_terminate(void) -{ - if (!_ereport_initialized) - return; - -#ifdef XP_UNIX - ereport(LOG_INFORM, XP_GetAdminStr(DBT_errorReportingShuttingDown_)); - if(PR_FileDesc2NativeHandle(_error_fd) != ERRORS_TO_SYSLOG) - system_fclose(_error_fd); - else - closelog(); -#else /* WIN32 */ - if(PR_FileDesc2NativeHandle(_error_fd) != NULL) - system_fclose(_error_fd); -#endif /* XP_UNIX */ - -} - - -/* ------------------------------- ereport -------------------------------- */ - - -static int degree_msg[] = { - DBT_warning_, - DBT_config_, - DBT_security_, - DBT_failure_, - DBT_catastrophe_, - DBT_info_, - DBT_verbose_ - }; - -#ifdef XP_UNIX -static int degree_syslog[] = { - LOG_WARNING, LOG_ERR, LOG_NOTICE, LOG_ALERT, LOG_CRIT, LOG_INFO, LOG_INFO -}; -#endif/* XP_UNIX */ - +/* taken from ACL plugin acl.h */ +#define ACL_PLUGIN_NAME "NSACLPlugin" NSAPI_PUBLIC int ereport_v(int degree, char *fmt, va_list args) { char errstr[MAX_ERROR_LEN]; - int pos = 0; - struct tm *tms, tmss; - time_t t; -#ifdef MCC_PROXY - char *p; - int i; -#endif /* MCC_PROXY */ - if (!_ereport_initialized) - return IO_OKAY; - -#ifdef XP_UNIX - if(PR_FileDesc2NativeHandle(_error_fd) != ERRORS_TO_SYSLOG) { -#endif /* XP_UNIX */ - t = time(NULL); - tms = system_localtime(&t, &tmss); - util_strftime(errstr, ERR_TIMEFMT, tms); - pos = strlen(errstr); - - pos += util_snprintf(&errstr[pos], MAX_ERROR_LEN - pos, " %s: ", - XP_GetAdminStr(degree_msg[degree])); -#ifdef XP_UNIX + util_vsnprintf(errstr, MAX_ERROR_LEN, fmt, args); + switch (degree) + { + case LOG_WARN: + case LOG_FAILURE: + case LOG_INFORM: + case LOG_VERBOSE: + case LOG_MISCONFIG: +// slapi_log_error(SLAPI_LOG_PLUGIN, ACL_PLUGIN_NAME, errstr); + break; + case LOG_SECURITY: +// slapi_log_error(SLAPI_LOG_ACL, ACL_PLUGIN_NAME, errstr); + break; + case LOG_CATASTROPHE: +// slapi_log_error(SLAPI_LOG_FATAL, ACL_PLUGIN_NAME, errstr); + break; + default: + break; } -#endif /* XP_UNIX */ - - pos += util_vsnprintf(&errstr[pos], sizeof(errstr) - pos, fmt, args); - - pos += util_snprintf(&errstr[pos], sizeof(errstr) - pos, ENDLINE); - -#ifdef MCC_PROXY - /* Thanx to netlib, the proxy sometimes generates multiline err msgs */ - for(p=errstr, i=pos-1; i>0; i--, p++) { - if (*p == '\n' || *p == '\r') *p = ' '; - } -#endif /* MCC_PROXY */ - -#if defined XP_UNIX - if(PR_FileDesc2NativeHandle(_error_fd) != ERRORS_TO_SYSLOG) - return system_fwrite_atomic(_error_fd, errstr, pos); - syslog(degree_syslog[degree], errstr); return IO_OKAY; -#elif defined XP_WIN32 /* XP_WIN32 */ - if(PR_FileDesc2NativeHandle(_error_fd) != NULL) - { -#ifdef MCC_HTTPD - /* also write to NT Event Log if error is serious */ - switch (degree) - { - case LOG_MISCONFIG: - case LOG_SECURITY: - case LOG_CATASTROPHE: - LogErrorEvent(NULL, EVENTLOG_ERROR_TYPE, - 0, MSG_BAD_PARAMETER, - errstr, NULL); - break; - default: - break; - } -#endif - return system_fwrite_atomic(_error_fd, errstr, pos); - } - else { /* log to the EventLogger */ - /* Write to the event logger... */ - switch (degree) { - case LOG_WARN: - LogErrorEvent(NULL, EVENTLOG_WARNING_TYPE, - 0, MSG_BAD_PARAMETER, - errstr, NULL); - break; - case LOG_MISCONFIG: - case LOG_SECURITY: - case LOG_FAILURE: - case LOG_CATASTROPHE: - LogErrorEvent(NULL, EVENTLOG_ERROR_TYPE, - 0, MSG_BAD_PARAMETER, - errstr, NULL); - break; - - case LOG_INFORM: - default: - LogErrorEvent(NULL, EVENTLOG_INFORMATION_TYPE, - 0, MSG_BAD_PARAMETER, - errstr, NULL); - break; - } - return (IO_OKAY); - } -#endif /* XP_WIN32 */ - } NSAPI_PUBLIC int ereport(int degree, char *fmt, ...) diff --git a/lib/base/eventlog.cpp b/lib/base/eventlog.cpp index b8762842..26149c1a 100644 --- a/lib/base/eventlog.cpp +++ b/lib/base/eventlog.cpp @@ -22,7 +22,6 @@ #include <stdlib.h> #include "netsite.h" #include "base/eventlog.h" -#include "frame/conf.h" #include <nt/regparms.h> #include <nt/messages.h> diff --git a/lib/base/file.cpp b/lib/base/file.cpp index 7382be46..0833cde5 100644 --- a/lib/base/file.cpp +++ b/lib/base/file.cpp @@ -13,7 +13,6 @@ #include "base/file.h" -#include "ereport.h" #ifdef BSD_RLIMIT #include <sys/time.h> #include <sys/resource.h> diff --git a/lib/base/lexer.cpp b/lib/base/lexer.cpp index e521c51f..18327d0a 100644 --- a/lib/base/lexer.cpp +++ b/lib/base/lexer.cpp @@ -13,7 +13,7 @@ */ #include "netsite.h" -#include "base/nsassert.h" +#include "prlog.h" #include "lexer_pvt.h" #include "base/lexer.h" @@ -104,7 +104,7 @@ int lex_class_create(int classc, char * classv[], void **pchtab) int i; /* class index */ /* Get number of bytes per bit vector */ - NS_ASSERT(classc > 0); + PR_ASSERT(classc > 0); bvbytes = (classc + 7) >> 3; /* Allocate the character class table */ @@ -137,7 +137,7 @@ int lex_class_create(int classc, char * classv[], void **pchtab) } /* Return pointer to table */ - NS_ASSERT(pchtab != NULL); + PR_ASSERT(pchtab != NULL); *pchtab = (void *)ct; return classc; @@ -273,7 +273,7 @@ int lex_token_new(pool_handle_t * pool, int initlen, int growlen, void **token) if (growlen > 0) lt->lt_inclen = growlen; - NS_ASSERT(token != NULL); + PR_ASSERT(token != NULL); *token = (void *)lt; return 0; @@ -533,8 +533,8 @@ int lex_token_append(void * token, int nbytes, char * src) int bufsize; int length; - NS_ASSERT(nbytes >= 0); - NS_ASSERT((src != NULL) || (nbytes == 0)); + PR_ASSERT(nbytes >= 0); + PR_ASSERT((src != NULL) || (nbytes == 0)); if (nbytes > 0) { diff --git a/lib/base/net.cpp b/lib/base/net.cpp index 0d15b121..1ccfdbd7 100644 --- a/lib/base/net.cpp +++ b/lib/base/net.cpp @@ -14,19 +14,9 @@ #include "netsite.h" -#include "prio.h" -#include "private/pprio.h" #include <nspr.h> -#include <frame/conf.h> -/* Removed for ns security integration -#include "sslio/sslio.h" -*/ - -#include "net.h" #include "util.h" -#include "daemon.h" /* child_exit */ -#include "ereport.h" /* error reporting */ #include <string.h> #ifdef XP_UNIX #include <arpa/inet.h> /* inet_ntoa */ @@ -39,521 +29,18 @@ extern "C" int gethostname (char *name, size_t namelen); #include <sys/ioctl.h> /* ioctl */ #endif -extern "C" { -#include "ssl.h" -} - -#if defined(OSF1) -#include <stropts.h> -#endif -#include "base/systems.h" -#include "base/dbtbase.h" - -#if defined(OSF1) -#include <stropts.h> -#endif - -#ifdef IRIX -#include <bstring.h> /* fd_zero uses bzero */ -#endif -#include "netio.h" - -net_io_t net_io_functions; -/* removed for ns security integration -#include "xp_error.h" -*/ - #include "libadmin/libadmin.h" -int net_enabledns = 1; -int net_enableAsyncDNS = 0; -int net_listenqsize = DAEMON_LISTEN_SIZE; -unsigned int NET_BUFFERSIZE = NET_DEFAULT_BUFFERSIZE; -unsigned int NET_READ_TIMEOUT = NET_DEFAULT_READ_TIMEOUT; -unsigned int NET_WRITE_TIMEOUT = NET_DEFAULT_WRITE_TIMEOUT; -unsigned int SSL_HANDSHAKE_TIMEOUT = SSL_DEFAULT_HANDSHAKE_TIMEOUT; - - -/* ------------------------------ net_init -------------------------------- */ -NSAPI_PUBLIC int net_init(int security_on) -{ - return 0; -} - -/* ------------------------------ net_socket ------------------------------ */ -NSAPI_PUBLIC SYS_NETFD net_socket(int domain, int type, int protocol) -{ - SYS_NETFD sock; - SYS_NETFD prsock; - - if (security_active) { - if (protocol == IPPROTO_TCP) - prsock = PR_NewTCPSocket(); - else - prsock = PR_NewUDPSocket(); - if(prsock) - sock = SSL_ImportFD(NULL, prsock); - else sock = NULL; - } - else { - if (protocol == IPPROTO_TCP) sock = PR_NewTCPSocket(); - else sock = PR_NewUDPSocket(); - } - - if (sock == NULL) - return (SYS_NETFD)SYS_NET_ERRORFD; - return sock; -} - - -/* ---------------------------- net_getsockopt ---------------------------- */ -NSAPI_PUBLIC int net_getsockopt(SYS_NETFD s, int level, int optname, - void *optval, int *optlen) -{ - return getsockopt(PR_FileDesc2NativeHandle(s), level, optname, - (char *)optval, (TCPLEN_T *)optlen); -} - - -/* ---------------------------- net_setsockopt ---------------------------- */ - - -NSAPI_PUBLIC int net_setsockopt(SYS_NETFD s, int level, int optname, - const void *optval, int optlen) -{ - return setsockopt(PR_FileDesc2NativeHandle(s), level, optname, - (const char *)optval, optlen); -} -/* ------------------------------ net_listen ------------------------------ */ - - -NSAPI_PUBLIC int net_listen(SYS_NETFD s, int backlog) -{ - return PR_Listen(s, backlog)==PR_FAILURE?IO_ERROR:0; -} - - -/* ------------------------- net_create_listener -------------------------- */ - - -NSAPI_PUBLIC SYS_NETFD net_create_listener(char *ipstr, int port) -{ - SYS_NETFD sd; - /* - struct sockaddr_in sa_server; - */ - PRNetAddr sa_server; - PRStatus status; - PRInt32 flags; - - if ((sd = net_socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == SYS_NET_ERRORFD) { - return SYS_NET_ERRORFD; - } - -#ifdef SOLARIS - /* - * unset NONBLOCK flag; - */ - /* Have no idea why Solaris want to unset NONBLOCK flag when it should - be in NON-BLOCK mode, and new NSPR20 does not give file descriptor - back, so the code are removed --- yjh - flags = fcntl(sd->osfd, F_GETFL, 0); - fcntl(sd->osfd, F_SETFL, flags & ~O_NONBLOCK); - */ -#endif - /* Convert to NSPR21 for ns security integration - ZERO((char *) &sa_server, sizeof(sa_server)); - sa_server.sin_family=AF_INET; - sa_server.sin_addr.s_addr = (ipstr ? inet_addr(ipstr) : htonl(INADDR_ANY)); - sa_server.sin_port=htons(port); - if(net_bind(sd, (struct sockaddr *) &sa_server,sizeof(sa_server)) < 0) { - return SYS_NET_ERRORFD; - } - net_listen(sd, net_listenqsize); - */ - - if (ipstr) { - status = PR_InitializeNetAddr(PR_IpAddrNull, port, &sa_server); - if (status == PR_SUCCESS) sa_server.inet.ip = inet_addr(ipstr); - else return SYS_NET_ERRORFD; - } - else { - status = PR_InitializeNetAddr(PR_IpAddrAny, port, &sa_server); - if (status == PR_FAILURE) return SYS_NET_ERRORFD; - } - - status = PR_Bind(sd, &sa_server); - if (status == PR_FAILURE) return SYS_NET_ERRORFD; - - - status = PR_Listen(sd, net_listenqsize); - if (status == PR_FAILURE) return SYS_NET_ERRORFD; - - return sd; -} -/* ------------------------------ net_select ------------------------------ */ - -/* -NSAPI_PUBLIC int net_select(int nfds, fd_set *r, fd_set *w, fd_set *e, - struct timeval *timeout) -{ - PR_fd_set rd, wr, ex; - int index; - int rv; - - if (nfds > (64*1024)) - return -1; - - PR_FD_ZERO(&rd); - PR_FD_ZERO(&wr); - PR_FD_ZERO(&ex); - - for (index=0; index<nfds; index++) { - if (FD_ISSET(index, r)) - PR_FD_NSET(index, &rd); - if (FD_ISSET(index, w)) - PR_FD_NSET(index, &wr); - if (FD_ISSET(index, e)) - PR_FD_NSET(index, &ex); - } - - rv = PR_Select(0, &rd, &wr, &ex, PR_SecondsToInterval(timeout->tv_sec)); - if (rv > 0) { - FD_ZERO(r); - FD_ZERO(w); - FD_ZERO(e); - for (index=0; index<nfds; index++) { - if (PR_FD_NISSET(index, &rd)) - FD_SET(index, r); - if (PR_FD_NISSET(index, &wr)) - FD_SET(index, w); - if (PR_FD_NISSET(index, &ex)) - FD_SET(index, e); - } - } - - return rv; -} -*/ - -NSAPI_PUBLIC int net_select(int nfds, fd_set *r, fd_set *w, fd_set *e, - struct timeval *timeout) -{ - return 1; -} - - -/* ----------------------------- net_isalive ------------------------------ */ - - -/* - * XXXmikep As suggested by shaver@ingenia.com. If everyone was POSIX - * compilent, a write() of 0 bytes would work as well - */ -NSAPI_PUBLIC int net_isalive(SYS_NETFD sd) -{ - char c; - if (PR_RecvFrom(sd, &c, 1, MSG_PEEK, NULL, 0) == -1 ) { - return 0; - } - return 1; -} - - -/* ------------------------------ net_connect ------------------------------ */ - -NSAPI_PUBLIC int net_connect(SYS_NETFD s, const void *sockaddr, int namelen) -{ - int rv; - - child_status(CHILD_WRITING); - rv = PR_Connect(s, (PRNetAddr *)sockaddr, PR_INTERVAL_NO_TIMEOUT); - child_status(CHILD_PROCESSING); - - return rv==PR_FAILURE?IO_ERROR:0; -} - - -/* ------------------------------ net_ioctl ------------------------------ */ - - -NSAPI_PUBLIC int net_ioctl(SYS_NETFD s, int tag, void *result) -{ -#if defined(NET_WINSOCK) - return ioctlsocket(PR_FileDesc2NativeHandle(s),tag,(unsigned long *)result); -#elif defined(XP_UNIX) - return ioctl(PR_FileDesc2NativeHandle(s), tag, result); -#else - write me; -#endif - -} -/* --------------------------- net_getpeername ---------------------------- */ - - -NSAPI_PUBLIC int net_getpeername(SYS_NETFD s, struct sockaddr *name, - int *namelen) -{ -#if defined (SNI) || defined (UnixWare) - return getpeername(PR_FileDesc2NativeHandle(s), name, (size_t *)namelen); -#else /* defined (SNI) || defined (UnixWare) */ - return getpeername(PR_FileDesc2NativeHandle(s), name, (TCPLEN_T *)namelen); -#endif /* defined (SNI) || defined (UnixWare) */ -} - - -/* ------------------------------ net_close ------------------------------- */ - - -NSAPI_PUBLIC int net_close(SYS_NETFD s) -{ - return PR_Close(s)==PR_FAILURE?IO_ERROR:0; -} - -NSAPI_PUBLIC int net_shutdown(SYS_NETFD s, int how) -{ - switch (how) { - case 0: - return PR_Shutdown(s, PR_SHUTDOWN_RCV); - break; - case 1: - return PR_Shutdown(s, PR_SHUTDOWN_SEND); - break; - case 2: - return PR_Shutdown(s, PR_SHUTDOWN_BOTH); - break; - default: - return -1; - } - - return 0; -} - - - -/* ------------------------------- net_bind ------------------------------- */ - -NSAPI_PUBLIC int net_bind(SYS_NETFD s, const struct sockaddr *name, - int namelen) -{ - return PR_Bind(s, (const PRNetAddr *)name)==PR_FAILURE?IO_ERROR:0; -} - - -/* ------------------------------ net_accept ------------------------------ */ - - -NSAPI_PUBLIC SYS_NETFD net_accept(SYS_NETFD sd, struct sockaddr *addr, - int *addrlen) -{ - SYS_NETFD sock = PR_Accept(sd, (PRNetAddr *)addr, PR_INTERVAL_NO_TIMEOUT); - - if (sock == NULL) - return SYS_NET_ERRORFD; - return sock; -} - -/* ------------------------------- net_read ------------------------------- */ - -NSAPI_PUBLIC int net_read(SYS_NETFD fd, char *buf, int sz, int timeout) -{ - int rv; - - if (timeout == NET_ZERO_TIMEOUT) - timeout = PR_INTERVAL_NO_WAIT; - else if (timeout == NET_INFINITE_TIMEOUT) - timeout = PR_INTERVAL_NO_TIMEOUT; - else - timeout = PR_SecondsToInterval(timeout); - - child_status(CHILD_READING); - rv = PR_Recv(fd, buf, sz, 0, timeout); - - child_status(CHILD_PROCESSING); - return rv; -} - - -/* ------------------------------ net_write ------------------------------- */ - -#ifndef NEEDS_WRITEV -int net_writev(SYS_NETFD fd, struct iovec *iov, int iov_size) -{ - int rv; - - child_status(CHILD_WRITING); - rv = PR_Writev(fd, (PRIOVec *)iov, iov_size, PR_INTERVAL_NO_TIMEOUT); - child_status(CHILD_PROCESSING); - return rv; -} - -#else /* NEEDS_WRITEV */ - -/* Since SSL and NT do not support writev(), we just emulate it. - * This does not lead to the optimal number of packets going out... - */ -int net_writev(SYS_NETFD fd, struct iovec *iov, int iov_size) -{ - int index; - - child_status(CHILD_WRITING); - - for (index=0; index<iov_size; index++) { - - /* net_write already does the buffer for nonblocked IO */ - if ( net_write(fd, iov[index].iov_base, iov[index].iov_len) ==IO_ERROR){ - child_status(CHILD_PROCESSING); - return IO_ERROR; - } - } - - child_status(CHILD_PROCESSING); - return IO_OKAY; -} -#endif /* NEEDS_WRITEV */ - - -NSAPI_PUBLIC int net_write(SYS_NETFD fd, char *buf, int sz) -{ - int rv; - - child_status(CHILD_WRITING); - rv = PR_Send(fd, buf, sz, 0, PR_INTERVAL_NO_TIMEOUT); - child_status(CHILD_PROCESSING); - if(rv < 0) { - return IO_ERROR; - } - return rv; -} - -NSAPI_PUBLIC int net_socketpair(SYS_NETFD *pair) -{ - return PR_NewTCPSocketPair(pair); -} - -#ifdef XP_UNIX -NSAPI_PUBLIC SYS_NETFD net_dup2(SYS_NETFD prfd, int osfd) -{ - SYS_NETFD newfd = NULL; - - if (prfd && PR_FileDesc2NativeHandle(prfd) != osfd) { - if (dup2(PR_FileDesc2NativeHandle(prfd), osfd) != -1) { - newfd = PR_ImportFile(osfd); - if (!newfd) - close(osfd); - } - } - - return newfd; -} - -NSAPI_PUBLIC int net_is_STDOUT(SYS_NETFD prfd) -{ - int fd = PR_FileDesc2NativeHandle(prfd); - if (fd == STDOUT_FILENO) return 1; - return 0; -} - -NSAPI_PUBLIC int net_is_STDIN(SYS_NETFD prfd) -{ - int fd = PR_FileDesc2NativeHandle(prfd); - if (fd == STDIN_FILENO) return 1; - return 0; -} - -#endif /* XP_UNIX */ - -/* -------------------------- Accept mutex crap --------------------------- */ - - -#ifndef NET_WINSOCK - - -#include "sem.h" -static SEMAPHORE mob_sem; -static int have_mob_sem; - - -void net_accept_enter(void) -{ - if(sem_grab(mob_sem) == -1) - ereport(LOG_CATASTROPHE, "sem_grab failed (%s)", system_errmsg()); - have_mob_sem = 1; -} - -int net_accept_tenter(void) -{ - int ret = sem_tgrab(mob_sem); - if(ret != -1) - have_mob_sem = 1; - return ret; -} - -void net_accept_exit(void) -{ - if(sem_release(mob_sem) == -1) - ereport(LOG_CATASTROPHE, "sem_release failed (%s)", system_errmsg()); - have_mob_sem = 0; -} - -#ifdef AIX -#undef accept -#define accept naccept -#endif - -void net_accept_texit(void) -{ - if(have_mob_sem && (sem_release(mob_sem) == -1)) - ereport(LOG_CATASTROPHE, "sem_release failed (%s)", system_errmsg()); - have_mob_sem = 0; -} - -int net_accept_init(int port) -{ - /* XXXMB how to translate this to nspr? */ - /* since SSL_AcceptHook is no longer in ns security (HCL_1_5), - so this is gone! (It does exist in HCL_101) - SSL_AcceptHook((SSLAcceptFunc)PR_Accept); - */ - have_mob_sem = 0; - mob_sem = sem_init("netsite", port); - return (mob_sem == SEM_ERROR ? -1 : 0); -} - -void net_accept_terminate(void) -{ - sem_terminate(mob_sem); -} - -#endif /* !NET_WINSOCK */ - - -/* ----------------------------- net_ip2host ------------------------------ */ - - -char *dns_ip2host(char *ip, int verify); - -NSAPI_PUBLIC char *net_ip2host(char *ip, int verify) -{ - if(!net_enabledns) - return NULL; - - return dns_ip2host(ip, verify); -} - - - /* ---------------------------- util_hostname ----------------------------- */ - #ifdef XP_UNIX #include <sys/param.h> #else /* WIN32 */ #define MAXHOSTNAMELEN 255 #endif /* XP_UNIX */ -/* Defined in dns.c */ +/* Defined in dns.cpp */ char *net_find_fqdn(PRHostEnt *p); NSAPI_PUBLIC char *util_hostname(void) @@ -575,4 +62,3 @@ NSAPI_PUBLIC char *util_hostname(void) return net_find_fqdn(&hent); } - diff --git a/lib/base/plist_pvt.h b/lib/base/plist_pvt.h index e4b861c5..3f18b4af 100644 --- a/lib/base/plist_pvt.h +++ b/lib/base/plist_pvt.h @@ -35,9 +35,6 @@ typedef struct PListStruct_s PListStruct_t; * the property value data. */ -#ifndef PBLOCK_H -#include "base/pblock.h" -#endif /* PBLOCK_H */ #include <stddef.h> struct PLValueStruct_s { diff --git a/lib/base/pool.cpp b/lib/base/pool.cpp index 56232e3f..e33acd44 100644 --- a/lib/base/pool.cpp +++ b/lib/base/pool.cpp @@ -27,9 +27,6 @@ #ifdef MALLOC_POOLS #include "base/pool.h" #include "base/ereport.h" -#include "base/session.h" -#include "frame/req.h" -#include "frame/http.h" #include "base/util.h" #include "base/crit.h" @@ -107,40 +104,11 @@ pool_internal_init() known_pools_lock = crit_init(); freelist_lock = crit_init(); } - } else - ereport(LOG_INFORM, XP_GetAdminStr(DBT_poolInitMemoryPoolsDisabled_)); - - return 0; -} - -NSAPI_PUBLIC int -pool_init(pblock *pb, Session *sn, Request *rq) -{ - char *str_free_size = pblock_findval("free-size", pb); - char *str_pool_disable = pblock_findval("disable", pb); - - if (str_free_size != NULL) { - if ( (freelist_max = atoi(str_free_size)) <= 0) { - ereport(LOG_WARN, XP_GetAdminStr(DBT_poolInitFreeSize0UsingD_), - MAX_FREELIST_SIZE); - freelist_max = MAX_FREELIST_SIZE; - } } - if (str_pool_disable && strcasecmp(str_pool_disable, "false") ) - pool_disable = 1; - else - pool_disable = 0; - - if (known_pools_lock == NULL) { - known_pools_lock = crit_init(); - freelist_lock = crit_init(); - } - - return REQ_PROCEED; + return 0; } - static block_t * _create_block(int size) { diff --git a/lib/base/system.cpp b/lib/base/system.cpp index e58538b4..d138b400 100644 --- a/lib/base/system.cpp +++ b/lib/base/system.cpp @@ -10,7 +10,7 @@ */ #include "netsite.h" -#include "base/nsassert.h" +#include "prlog.h" #include "base/ereport.h" #ifdef XP_WIN32 @@ -52,6 +52,7 @@ static int thread_malloc_key = -1; #define DEBUG_FREE_CHAR 'X' #endif /* DEBUG_MALLOC */ + /* On NT, the server version string is not statically encoded based * upon a product compile define but dynamically set by the server * exe at startup. @@ -113,14 +114,14 @@ NSAPI_PUBLIC void system_free(void *ptr) #if defined(MALLOC_POOLS) && defined(MCC_HTTPD) && defined(THREAD_ANY) pool_free(MALLOC_KEY, ptr); #else - NS_ASSERT(ptr); + PR_ASSERT(ptr); free(ptr); #endif } NSAPI_PUBLIC char *system_strdup(const char *ptr) { - NS_ASSERT(ptr); + PR_ASSERT(ptr); #if defined(MALLOC_POOLS) && defined(MCC_HTTPD) && defined(THREAD_ANY) return pool_strdup(MALLOC_KEY, ptr); #else @@ -202,7 +203,7 @@ NSAPI_PUBLIC void system_free_perm(void *ptr) char *baseptr, *cptr; int index; - NS_ASSERT(ptr); + PR_ASSERT(ptr); cptr = baseptr = ((char *)ptr) - DEBUG_MARGIN - 2*sizeof(int); @@ -239,7 +240,7 @@ NSAPI_PUBLIC void system_free_perm(void *ptr) NSAPI_PUBLIC char *system_strdup_perm(const char *ptr) { #ifndef DEBUG_MALLOC - NS_ASSERT(ptr); + PR_ASSERT(ptr); return strdup(ptr); #else int len = strlen(ptr); diff --git a/lib/base/systhr.cpp b/lib/base/systhr.cpp index ac29121a..169405d6 100644 --- a/lib/base/systhr.cpp +++ b/lib/base/systhr.cpp @@ -10,7 +10,6 @@ */ #include "systhr.h" -#include "ereport.h" #define USE_NSPR #ifdef USE_NSPR diff --git a/lib/base/util.cpp b/lib/base/util.cpp index 55d6ca56..d775e00f 100644 --- a/lib/base/util.cpp +++ b/lib/base/util.cpp @@ -20,625 +20,12 @@ #include "base/util.h" #include "base/dbtbase.h" -#include "base/ereport.h" #ifdef XP_UNIX #include <sys/types.h> #endif /* WIN32 */ -/* ----------------------------- util_getline ----------------------------- */ - -#define LF 10 -#define CR 13 - -NSAPI_PUBLIC int util_getline(filebuf_t *buf, int lineno, int maxlen, char *l) { - int i, x; - - x = 0; - while(1) { - i = filebuf_getc(buf); - switch(i) { - case IO_EOF: - l[x] = '\0'; - return 1; - case LF: - if(x && (l[x-1] == '\\')) { - --x; - continue; - } - l[x] = '\0'; - return 0; - case IO_ERROR: - util_sprintf(l, "I/O error reading file at line %d", lineno); - return -1; - case CR: - continue; - default: - l[x] = (char) i; - if(++x == maxlen) { - util_sprintf(l, "line %d is too long", lineno); - return -1; - } - break; - } - } -} - - -/* ---------------------------- util_can_exec ----------------------------- */ - -#ifdef XP_UNIX -NSAPI_PUBLIC int util_can_exec(struct stat *fi, uid_t uid, gid_t gid) -{ - if(!uid) - return 1; - if((fi->st_mode & S_IXOTH) || - ((gid == fi->st_gid) && (fi->st_mode & S_IXGRP)) || - ((uid == fi->st_uid) && (fi->st_mode & S_IXUSR))) - return 1; - return 0; -} -#endif /* XP_UNIX */ - - -/* --------------------------- util_env_create ---------------------------- */ - - -NSAPI_PUBLIC char **util_env_create(char **env, int n, int *pos) -{ - int x; - - if(!env) { - *pos = 0; - return (char **) MALLOC((n + 1)*sizeof(char *)); - } - else { - for(x = 0; (env[x]); x++); - env = (char **) REALLOC(env, (n + x + 1)*(sizeof(char *))); - *pos = x; - return env; - } -} - - -/* ---------------------------- util_env_free ----------------------------- */ - - -NSAPI_PUBLIC void util_env_free(char **env) -{ - register char **ep = env; - - for(ep = env; *ep; ep++) - FREE(*ep); - FREE(env); -} - -/* ----------------------------- util_env_str ----------------------------- */ - - -NSAPI_PUBLIC char *util_env_str(char *name, char *value) { - char *t,*tp; - - t = (char *) MALLOC(strlen(name)+strlen(value)+2); /* 2: '=' and '\0' */ - - for(tp=t; (*tp = *name); tp++,name++); - for(*tp++ = '='; (*tp = *value); tp++,value++); - return t; -} - - -/* --------------------------- util_env_replace --------------------------- */ - - -NSAPI_PUBLIC void util_env_replace(char **env, char *name, char *value) -{ - int x, y, z; - char *i; - - for(x = 0; env[x]; x++) { - i = strchr(env[x], '='); - *i = '\0'; - if(!strcmp(env[x], name)) { - y = strlen(env[x]); - z = strlen(value); - - env[x] = (char *) REALLOC(env[x], y + z + 2); - util_sprintf(&env[x][y], "=%s", value); - return; - } - *i = '='; - } -} - - -/* ---------------------------- util_env_find ----------------------------- */ - - -NSAPI_PUBLIC char *util_env_find(char **env, char *name) -{ - char *i; - int x, r; - - for(x = 0; env[x]; x++) { - i = strchr(env[x], '='); - *i = '\0'; - r = !strcmp(env[x], name); - *i = '='; - if(r) - return i + 1; - } - return NULL; -} - - -/* ---------------------------- util_env_copy ----------------------------- */ - - -NSAPI_PUBLIC char **util_env_copy(char **src, char **dst) -{ - char **src_ptr; - int src_cnt; - int index; - - if (!src) - return NULL; - - for (src_cnt = 0, src_ptr = src; *src_ptr; src_ptr++, src_cnt++); - - if (!src_cnt) - return NULL; - - dst = util_env_create(dst, src_cnt, &index); - - for (src_ptr = src, index=0; *src_ptr; index++, src_ptr++) - dst[index] = STRDUP(*src_ptr); - dst[index] = NULL; - - return dst; -} - -/* ---------------------------- util_hostname ----------------------------- */ - - -/* - * MOVED TO NET.C TO AVOID INTERDEPENDENCIES - */ - - -/* --------------------------- util_chdir2path ---------------------------- */ - - -NSAPI_PUBLIC int util_chdir2path(char *path) -{ - /* use FILE_PATHSEP to accomodate WIN32 */ - char *t = strrchr(path, FILE_PATHSEP); - int ret; - - if(!t) - return -1; - - *t = '\0'; -#ifdef XP_UNIX - ret = chdir(path); -#else /* WIN32 */ - ret = SetCurrentDirectory(path); -#endif /* XP_UNIX */ - - /* use FILE_PATHSEP instead of chdir to accomodate WIN32 */ - *t = FILE_PATHSEP; - - return ret; -} - - -/* --------------------------- util_is_mozilla ---------------------------- */ - - -NSAPI_PUBLIC int util_is_mozilla(char *ua, char *major, char *minor) -{ - if((!ua) || strncasecmp(ua, "Mozilla/", 8)) - return 0; - - /* Major version. I punted on supporting versions like 10.0 */ - if(ua[8] > major[0]) - return 1; - else if((ua[8] < major[0]) || (ua[9] != '.')) - return 0; - - /* Minor version. Support version numbers like 0.96 */ - if(ua[10] < minor[0]) - return 0; - else if((ua[10] > minor[0]) || (!minor[1])) - return 1; - - if((!isdigit(ua[11])) || (ua[11] < minor[1])) - return 0; - else - return 1; -} - - -/* ----------------------------- util_is_url ------------------------------ */ - - -#include <ctype.h> /* isalpha */ - -NSAPI_PUBLIC int util_is_url(char *url) -{ - char *t = url; - - while(*t) { - if(*t == ':') - return 1; - if(!isalpha(*t)) - return 0; - ++t; - } - return 0; -} - - -/* --------------------------- util_later_than ---------------------------- */ - - -int _mstr2num(char *str) { - if(!strcasecmp(str, "Jan")) return 0; - if(!strcasecmp(str, "Feb")) return 1; - if(!strcasecmp(str, "Mar")) return 2; - if(!strcasecmp(str, "Apr")) return 3; - if(!strcasecmp(str, "May")) return 4; - if(!strcasecmp(str, "Jun")) return 5; - if(!strcasecmp(str, "Jul")) return 6; - if(!strcasecmp(str, "Aug")) return 7; - if(!strcasecmp(str, "Sep")) return 8; - if(!strcasecmp(str, "Oct")) return 9; - if(!strcasecmp(str, "Nov")) return 10; - if(!strcasecmp(str, "Dec")) return 11; - return -1; -} - -int _time_compare(struct tm *lms, char *ims, int later_than_op) -{ - int y = 0, mnum = 0, d = 0, h = 0, m = 0, s = 0, x; - char t[128]; - - /* Supported formats start with weekday (which we don't care about) */ - /* The sizeof(t) is to avoid buffer overflow with t */ - if((!(ims = strchr(ims,' '))) || (strlen(ims) > (sizeof(t) - 2))) - return 0; - - while(*ims && isspace(*ims)) ++ims; - if((!(*ims)) || (strlen(ims) < 2)) - return 0; - - /* Standard HTTP (RFC 850) starts with dd-mon-yy */ - if(ims[2] == '-') { - sscanf(ims, "%s %d:%d:%d", t, &h, &m, &s); - if(strlen(t) < 6) - return 0; - t[2] = '\0'; - t[6] = '\0'; - d = atoi(t); - mnum = _mstr2num(&t[3]); - x = atoi(&t[7]); - /* Postpone wraparound until 2070 */ - y = x + (x < 70 ? 2000 : 1900); - } - /* The ctime format starts with a month name */ - else if(isalpha(*ims)) { - sscanf(ims,"%s %d %d:%d:%d %*s %d", t, &d, &h, &m, &s, &y); - mnum = _mstr2num(t); - } - /* RFC 822 */ - else { - sscanf(ims, "%d %s %d %d:%d:%d", &d, t, &y, &h, &m, &s); - mnum = _mstr2num(t); - } - - if (later_than_op) { - if( (x = (1900 + lms->tm_year) - y) ) - return x < 0; - - if(mnum == -1) - return 0; - - /* XXXMB - this will fail if you check if december 31 1996 is later - * than january 1 1997 - */ - if((x = lms->tm_mon - mnum) || (x = lms->tm_mday - d) || - (x = lms->tm_hour - h) || (x = lms->tm_min - m) || - (x = lms->tm_sec - s)) - return x < 0; - - return 1; - } - else { - return (mnum != -1 && - 1900 + lms->tm_year == y && - lms->tm_mon == mnum && - lms->tm_mday == d && - lms->tm_hour == h && - lms->tm_min == m && - lms->tm_sec == s); - } -} - - -/* Returns 0 if lms later than ims - * Returns 1 if equal - * Returns 1 if ims later than lms - */ -NSAPI_PUBLIC int util_later_than(struct tm *lms, char *ims) -{ - return _time_compare(lms, ims, 1); -} - - -NSAPI_PUBLIC int util_time_equal(struct tm *lms, char *ims) -{ - return _time_compare(lms, ims, 0); -} - -/* util_str_time_equal() - * - * Function to compare if two time strings are equal - * - * Acceptible date formats: - * Saturday, 17-Feb-96 19:41:34 GMT <RFC850> - * Sat, 17 Mar 1996 19:41:34 GMT <RFC1123> - * - * Argument t1 MUST be RFC1123 format. - * - * Note- it is not the intention of this routine to *always* match - * There are cases where we would return != when the strings might - * be equal (especially with case). The converse should not be true. - * - * Return 0 if equal, -1 if not equal. - */ -#define MINIMUM_LENGTH 18 -#define RFC1123_DAY 5 -#define RFC1123_MONTH 8 -#define RFC1123_YEAR 12 -#define RFC1123_HOUR 17 -#define RFC1123_MINUTE 20 -#define RFC1123_SECOND 23 -NSAPI_PUBLIC int util_str_time_equal(char *t1, char *t2) -{ - int index; - - /* skip over leading whitespace... */ - while(*t1 && isspace(*t1)) ++t1; - while(*t2 && isspace(*t2)) ++t2; - - /* Check weekday */ - if ( (t1[0] != t2[0]) || (t1[1] != t2[1]) ) - return -1; - - /* Skip to date */ - while(*t2 && !isspace(*t2)) ++t2; - t2++; - - /* skip if not strings not long enough */ - if ( (strlen(t1) < MINIMUM_LENGTH) || (strlen(t2) < MINIMUM_LENGTH) ) - return -1; - - if ( (t1[RFC1123_DAY] != t2[0]) || (t1[RFC1123_DAY+1] != t2[1]) ) - return -1; - - /* Skip to the month */ - t2 += 3; - - if ( (t1[RFC1123_MONTH] != t2[0]) || (t1[RFC1123_MONTH+1] != t2[1]) || - (t1[RFC1123_MONTH+2] != t2[2]) ) - return -1; - - /* Skip to year */ - t2 += 4; - - if ( (t1[RFC1123_YEAR] != t2[0]) ) { - /* Assume t2 is RFC 850 format */ - if ( (t1[RFC1123_YEAR+2] != t2[0]) || (t1[RFC1123_YEAR+3] != t2[1]) ) - return -1; - - /* skip to hour */ - t2 += 3; - } else { - /* Assume t2 is RFC 1123 format */ - if ( (t1[RFC1123_YEAR+1] != t2[1]) || (t1[RFC1123_YEAR+2] != t2[2]) || - (t1[RFC1123_YEAR+3] != t2[3]) ) - return -1; - - /* skip to hour */ - t2 += 5; - } - - /* check date */ - for (index=0; index<8; index++) { - if ( t1[RFC1123_HOUR+index] != t2[index] ) - return -1; - } - - /* Ignore timezone */ - - return 0; -} - - -/* --------------------------- util_uri_is_evil --------------------------- */ - - -NSAPI_PUBLIC int util_uri_is_evil(char *t) -{ - register int x; - - for(x = 0; t[x]; ++x) { - if(t[x] == '/') { - if(t[x+1] == '/') - return 1; - if(t[x+1] == '.') { - switch(t[x+2]) { - case '.': - if((!t[x+3]) || (t[x+3] == '/')) - return 1; - case '/': - case '\0': - return 1; - } - } - } -#ifdef XP_WIN32 - /* On NT, the directory "abc...." is the same as "abc" - * The only cheap way to catch this globally is to disallow - * names with the trailing "."s. Hopefully this is not over - * restrictive - */ - if ((t[x] == '.') && ( (t[x+1] == '/') || (t[x+1] == '\0') )) { - return 1; - } -#endif - } - return 0; -} - -/* ---------------------------- util_uri_parse ---------------------------- */ - -NSAPI_PUBLIC void util_uri_parse(char *uri) -{ - int spos = 0, tpos = 0; - int l = strlen(uri); - - while(uri[spos]) { - if(uri[spos] == '/') { - if((spos != l) && (uri[spos+1] == '.')) { - if(uri[spos+2] == '/') - spos += 2; - else - if((spos <= (l-3)) && - (uri[spos+2] == '.') && (uri[spos+3] == '/')) { - spos += 3; - while((tpos > 0) && (uri[--tpos] != '/')) - uri[tpos] = '\0'; - } else - uri[tpos++] = uri[spos++]; - } else { - if(uri[spos+1] != '/') - uri[tpos++] = uri[spos++]; - else - spos++; - } - } else - uri[tpos++] = uri[spos++]; - } - uri[tpos] = '\0'; -} - - -/* -------------------- util_uri_unescape_and_normalize -------------------- */ - -#ifdef XP_WIN32 -/* The server calls this function to unescape the URI and also normalize - * the uri. Normalizing the uri converts all "\" characters in the URI - * and pathinfo portion to "/". Does not touch "\" in query strings. - */ -void util_uri_unescape_and_normalize(char *s) -{ - char *t, *u; - - for(t = s, u = s; *t; ++t, ++u) { - if((*t == '%') && t[1] && t[2]) { - *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A')+10 : (t[1] - '0'))*16) + - (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A')+10 : (t[2] - '0')); - t += 2; - } - else - if(u != t) - *u = *t; - if (*u == '\\') /* normalize */ - *u = '/'; - } - *u = *t; -} -#endif /* XP_WIN32 */ - -/* -------------------------- util_uri_unescape --------------------------- */ - -NSAPI_PUBLIC void util_uri_unescape(char *s) -{ - char *t, *u; - - for(t = s, u = s; *t; ++t, ++u) { - if((*t == '%') && t[1] && t[2]) { - *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A')+10 : (t[1] - '0'))*16) + - (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A')+10 : (t[2] - '0')); - t += 2; - } - else - if(u != t) - *u = *t; - } - *u = *t; -} - - -/* --------------------------- util_uri_escape ---------------------------- */ - - -NSAPI_PUBLIC char *util_uri_escape(char *od, char *s) -{ - char *d; - - if(!od) - od = (char *) MALLOC((strlen(s)*3) + 1); - d = od; - - while(*s) { - if(strchr("% ?#:+&*\"<>\r\n", *s)) { - sprintf(d, "%%%2x", *s); - ++s; d += 3; - } - else - *d++ = *s++; - } - *d = '\0'; - return od; -} - - -/* --------------------------- util_url_escape ---------------------------- */ - - -NSAPI_PUBLIC char *util_url_escape(char *od, char *s) -{ - char *d; - - if(!od) - od = (char *) MALLOC((strlen(s)*3) + 1); - d = od; - - while(*s) { - if(strchr("% +*\"<>\r\n", *s)) { - sprintf(d, "%%%.2x", *s); - ++s; d += 3; - } - else - *d++ = *s++; - } - *d = '\0'; - return od; -} - - -/* ------------------------- util_mime_separator -------------------------- */ - - -NSAPI_PUBLIC int util_mime_separator(char *sep) -{ - srand(time(NULL)); - return util_sprintf(sep, "%c%c--%d%d%d", CR, LF, rand(), rand(), rand()); -} - - /* ------------------------------ util_itoa ------------------------------- */ @@ -714,23 +101,6 @@ NSAPI_PUBLIC int util_sprintf(char *s, const char *fmt, ...) return PR_vsnprintf(s, UTIL_PRF_MAXSIZE, fmt, args); } -/* ---------------------------- util_sh_escape ---------------------------- */ - - -NSAPI_PUBLIC char *util_sh_escape(char *s) -{ - char *ns = (char *) MALLOC(strlen(s) * 2 + 1); /* worst case */ - register char *t, *u; - - for(t = s, u = ns; *t; ++t, ++u) { - if(strchr("&;`'\"|*?~<>^()[]{}$\\ #!", *t)) - *u++ = '\\'; - *u = *t; - } - *u = '\0'; - return ns; -} - /* --------------------------- util_strcasecmp ---------------------------- */ @@ -777,67 +147,6 @@ int util_strncasecmp(CASECMPARG_T char *one, CASECMPARG_T char *two, int n) } #endif /* NEED_STRNCASECMP */ -#ifdef XP_WIN32 - - -/* util_delete_directory() - * This routine deletes all the files in a directory. If delete_directory is - * TRUE it will also delete the directory itself. - */ -VOID -util_delete_directory(char *FileName, BOOL delete_directory) -{ - HANDLE firstFile; - WIN32_FIND_DATA findData; - char *TmpFile, *NewFile; - - if (FileName == NULL) - return; - - TmpFile = (char *)MALLOC(strlen(FileName) + 5); - sprintf(TmpFile, "%s\\*.*", FileName); - firstFile = FindFirstFile(TmpFile, &findData); - FREE(TmpFile); - - if (firstFile == INVALID_HANDLE_VALUE) - return; - - if(strcmp(findData.cFileName, ".") && - strcmp(findData.cFileName, "..")) { - NewFile = (char *)MALLOC(strlen(FileName) + 1 + - strlen(findData.cFileName) + 1); - sprintf(NewFile, "%s\\%s",FileName, findData.cFileName); - DeleteFile(NewFile); - FREE(NewFile); - } - while (TRUE) { - if(!(FindNextFile(firstFile, &findData))) { - if (GetLastError() != ERROR_NO_MORE_FILES) { - ereport(LOG_WARN, XP_GetAdminStr(DBT_couldNotRemoveTemporaryDirectory_), FileName, GetLastError()); - } else { - FindClose(firstFile); - if (delete_directory) - if(!RemoveDirectory(FileName)) { - ereport(LOG_WARN, - XP_GetAdminStr(DBT_couldNotRemoveTemporaryDirectory_1), - FileName, GetLastError()); - } - return; - } - } else { - if(strcmp(findData.cFileName, ".") && - strcmp(findData.cFileName, "..")) { - NewFile = (char *)MALLOC(strlen(FileName) + 5 + - strlen(findData.cFileName) + 1); - sprintf(NewFile,"%s\\%s", FileName, findData.cFileName); - DeleteFile(NewFile); - FREE(NewFile); - } - } - } -} -#endif - /* ------------------------------ util_strftime --------------------------- */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -1118,30 +427,6 @@ _util_strftime_conv(char *pt, int n, int digits, char pad) return; } - -#ifdef XP_UNIX -/* - * Local Thread Safe version of waitpid. This prevents the process - * from blocking in the system call. - */ -NSAPI_PUBLIC pid_t -util_waitpid(pid_t pid, int *statptr, int options) -{ - pid_t rv; - - for(rv = 0; !rv; PR_Sleep(500)) { - rv = waitpid(pid, statptr, options | WNOHANG); - if (rv == -1) { - if (errno == EINTR) - rv = 0; /* sleep and try again */ - else - ereport(LOG_WARN, "waitpid failed for pid %d:%s", pid, system_errmsg()); - } - } - return rv; -} -#endif - /* * Various reentrant routines by mikep. See util.h and systems.h */ @@ -1164,111 +449,6 @@ util_waitpid(pid_t pid, int *statptr, int options) #endif -NSAPI_PUBLIC char * -util_strtok(register char *s, - register const char *delim, - register char **lasts) -{ -#ifdef HAVE_STRTOK_R - return strtok_r(s, delim, lasts); -#else - /* - * THIS IS THE THREAD SAFE VERSION OF strtok captured from - * public NetBSD. Note that no locks are needed - */ - register char *spanp; - register int c, sc; - char *tok; - - if (s == NULL && (s = *lasts) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), - * sort of). - */ - -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { - if (c == sc) - goto cont; - } - - if (c == 0) { /* no non-delimiter characters */ - *lasts = NULL; - return (NULL); - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), - * sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) { - c = *s++; - spanp = (char *)delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *lasts = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -#endif /* no strtok_r */ -} - -#ifndef XP_WIN32 -NSAPI_PUBLIC struct passwd * -util_getpwnam(const char *name, struct passwd *result, char *buffer, - int buflen) -{ -#ifdef HAVE_PW_R - -#ifdef AIX -#if OSVERSION >= 4320 - return ((int)getpwnam_r(name, result, buffer, buflen, 0) == 0 ? result : NULL); -#else - return ((int)getpwnam_r(name, result, buffer, buflen) == 0 ? result : NULL); -#endif -#else - return getpwnam_r(name, result, buffer, buflen); -#endif /* AIX */ - -#else - char *lastp; - struct passwd *r; - RE_LOCK(pw); - r = getpwnam(name); - if (!r) - return r; - - result->pw_gid = r->pw_gid; - result->pw_uid = r->pw_uid; - /* Hope this buffer is long enough */ - if (buffer) - util_snprintf(buffer, buflen, "%s:%s:%d:%d:%s:%s:%s", r->pw_name, r->pw_passwd, - r->pw_uid, r->pw_gid, r->pw_gecos, r->pw_dir, r->pw_shell); - RE_UNLOCK(pw); - - result->pw_name = util_strtok(buffer, ":", &lastp); - result->pw_passwd = util_strtok(NULL, ":", &lastp); - (void) util_strtok(NULL, ":", &lastp); - (void) util_strtok(NULL, ":", &lastp); - result->pw_gecos = util_strtok(NULL, ":", &lastp); - result->pw_dir = util_strtok(NULL, ":", &lastp); - result->pw_shell = util_strtok(NULL, ":", &lastp); - return result; -#endif -} -#endif - NSAPI_PUBLIC struct tm * util_localtime(const time_t *clock, struct tm *res) { @@ -1290,160 +470,3 @@ util_localtime(const time_t *clock, struct tm *res) return res; #endif } - - -NSAPI_PUBLIC char * -util_ctime(const time_t *clock, char *buf, int buflen) -{ -/* - * From cgi-src/restore.c refering to XP_WIN32: - * MLM - gross, but it works, better now FLC - */ -#if !defined(HAVE_TIME_R) || defined(XP_WIN32) - RE_LOCK(ctime); - strncpy(buf, ctime(clock), buflen); - buf[buflen - 1] = '\0'; - RE_UNLOCK(ctime); - return buf; -#elif HAVE_TIME_R == 2 - return ctime_r(clock, buf); -#else /* HAVE_TIME_R == 3 */ - return ctime_r(clock, buf, buflen); -#endif -} - -NSAPI_PUBLIC struct tm * -util_gmtime(const time_t *clock, struct tm *res) -{ -#ifdef HAVE_TIME_R - return gmtime_r(clock, res); -#else - struct tm *rv; - time_t zero = 0x7fffffff; - - RE_LOCK(gmtime); - rv = gmtime(clock); - RE_UNLOCK(gmtime); - if (!rv) - rv = gmtime(&zero); - if (rv) - *res = *rv; - else - return NULL; - - return res; -#endif -} - -NSAPI_PUBLIC char * -util_asctime(const struct tm *tm, char *buf, int buflen) -{ -#if HAVE_TIME_R == 2 - return asctime_r(tm, buf); -#elif HAVE_TIME_R == 3 - return asctime_r(tm, buf, buflen); -#else - RE_LOCK(asctime); - strncpy(buf, asctime(tm), buflen); - buf[buflen - 1] = '\0'; - RE_UNLOCK(asctime); - return buf; -#endif -} - -NSAPI_PUBLIC char * -util_strerror(int errnum, char *msg, int buflen) -{ -#ifdef HAVE_STRERROR_R - /* More IBM real-genius */ - return ((int)strerror_r(errnum, msg, buflen) > 0) ? msg : NULL; -#else - /* RE_LOCK(strerror); I don't think this is worth the trouble */ - (void)strncpy(msg, strerror(errnum), buflen); - msg[buflen - 1] = '\0'; - return msg; - /* RE_UNLOCK(strerror); */ -#endif -} - - - -/* ------------------------------- OLD CODE ------------------------------- */ - - -#if 0 - -NSAPI_PUBLIC int util_vsnprintf(char *s, int n, register char *fmt, - va_list args) -{ - register int pos = 0, max = (n > 2 ? n-2 : -1), boundson; - register char c, *t; - - if((max == -1) && (n != -1)) - goto punt; - - boundson = (n != -1); - while(*fmt) { - if(boundson && (pos > max)) - break; - c = *fmt++; - switch(c) { - case '%': - switch(*fmt++) { - case 'd': - if(boundson && ((pos + 10) > max)) - goto punt; - pos += util_itoa(va_arg(args, int), &s[pos]); - break; - case 's': - t = va_arg(args, char *); - while(*t) { - s[pos++] = *t++; - if(boundson && (pos > max)) - goto punt; - } - break; - case 'c': - s[pos++] = (char) va_arg(args, int); - break; - case '%': - s[pos++] = '%'; - break; - } - break; - case '\\': - if( (s[pos++] = *fmt) ) - ++fmt; - break; - default: - s[pos++] = c; - } - } - punt: - s[pos] = '\0'; - - va_end(args); - return pos; -} - -NSAPI_PUBLIC int util_snprintf(char *s, int n, char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - return util_vsnprintf(s, n, fmt, args); -} - -NSAPI_PUBLIC int util_vsprintf(char *s, register char *fmt, va_list args) -{ - return util_vsnprintf(s, -1, fmt, args); -} - -NSAPI_PUBLIC int util_sprintf(char *s, char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - return util_vsnprintf(s, -1, fmt, args); -} -#endif diff --git a/lib/libaccess/Makefile b/lib/libaccess/Makefile index 2acb484b..c5433f7f 100644 --- a/lib/libaccess/Makefile +++ b/lib/libaccess/Makefile @@ -43,14 +43,8 @@ OBJS=$(addprefix $(OBJDEST)/, usi.o \ attrec.o \ nseframe.o \ nsdb.o \ - nsdbmgmt.o \ nsuser.o \ - nsumgmt.o \ nsgroup.o \ - nsgmgmt.o \ - nsadb.o \ - nscert.o \ - nsamgmt.o \ nsautherr.o \ symbols.o \ acltools.o \ @@ -67,7 +61,6 @@ OBJS=$(addprefix $(OBJDEST)/, usi.o \ usrcache.o \ lasgroup.o \ lasuser.o \ - lasprogram.o \ aclspace.o \ acl.tab.o \ acl.yy.o \ @@ -77,10 +70,15 @@ OBJS=$(addprefix $(OBJDEST)/, usi.o \ aclparse.o \ aclbuild.o \ aclerror.o \ - acladmin.o \ - aclcgi.o \ + nsadb.o \ + nscert.o \ + nsamgmt.o \ + nsgmgmt.o \ + nsdbmgmt.o \ + nsumgmt.o \ $(OSOBJS) \ ) + # # AVA Mapping files. Currently not compiled in (FORTEZZA for reference only). diff --git a/lib/libaccess/aclcache.cpp b/lib/libaccess/aclcache.cpp index 34d2ecfb..acb1fc1d 100644 --- a/lib/libaccess/aclcache.cpp +++ b/lib/libaccess/aclcache.cpp @@ -4,7 +4,7 @@ * All rights reserved. * END COPYRIGHT BLOCK **/ -#include <base/nsassert.h> +#include <prlog.h> #include <base/crit.h> #include <base/ereport.h> #include <plhash.h> @@ -125,20 +125,20 @@ ACL_ListHashUpdate(ACLListHandle_t **acllistp) NSErr_t *errp = 0; ACLListHandle_t *tmp_acllist; - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); tmp_acllist = (ACLListHandle_t *)PR_HashTableLookup(ACLListHash, *acllistp); if (tmp_acllist && tmp_acllist != *acllistp) { - NS_ASSERT(*acllistp && *acllistp != ACL_LIST_NO_ACLS); + PR_ASSERT(*acllistp && *acllistp != ACL_LIST_NO_ACLS); ACL_ListDestroy(errp, *acllistp); *acllistp = tmp_acllist; - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); tmp_acllist->ref_count++; /* we're gonna use it */ } else { /* Wasn't in the list */ PR_HashTableAdd(ACLListHash, *acllistp, *acllistp); } - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return; } @@ -156,15 +156,15 @@ ACL_ListHashEnter(ACLListHandle_t **acllistp) /* Look for a matching ACL List and use it if we find one. */ if (*acllistp) { - NS_ASSERT(*acllistp != ACL_LIST_NO_ACLS); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(*acllistp != ACL_LIST_NO_ACLS); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); ACL_ListHashUpdate(acllistp); } else { *acllistp = ACL_LIST_NO_ACLS; } ACL_CritExit(); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return; } @@ -184,12 +184,12 @@ ACL_ListHashCheck(ACLListHandle_t **acllistp) tmp_acllist = (ACLListHandle_t *)PR_HashTableLookup(ACLListHash, *acllistp); if (tmp_acllist) { - NS_ASSERT(*acllistp && *acllistp != ACL_LIST_NO_ACLS); + PR_ASSERT(*acllistp && *acllistp != ACL_LIST_NO_ACLS); *acllistp = tmp_acllist; - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); tmp_acllist->ref_count++; /* we're gonna use it */ ACL_CritExit(); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return 1; /* Normal path */ } else { /* Wasn't in the list */ ACL_CritExit(); @@ -280,7 +280,7 @@ int ACL_INTCacheCheck(int which, char *uri, ACLListHandle_t **acllistp) { PLHashTable *hash; - NS_ASSERT(uri && acl_uri_hash && acl_uri_get_hash); + PR_ASSERT(uri && acl_uri_hash && acl_uri_get_hash); /* ACL cache: If the ACL List is already in the cache, there's no need * to go through the pathcheck directives. @@ -300,12 +300,12 @@ ACL_INTCacheCheck(int which, char *uri, ACLListHandle_t **acllistp) *acllistp = (ACLListHandle_t *)PR_HashTableLookup(hash, uri); if (*acllistp != NULL) { if (*acllistp != ACL_LIST_NO_ACLS) { - NS_ASSERT((*acllistp)->ref_count >= 0); - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT((*acllistp)->ref_count >= 0); + PR_ASSERT(ACL_CritHeld()); (*acllistp)->ref_count++; } ACL_CritExit(); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return 1; /* Normal path */ } @@ -339,7 +339,7 @@ ACL_INTCacheEnter(int which, char *uri, ACLListHandle_t **acllistp) NSErr_t *errp = 0; PLHashTable *hash; - NS_ASSERT(uri); + PR_ASSERT(uri); ACL_CritEnter(); @@ -356,7 +356,7 @@ ACL_INTCacheEnter(int which, char *uri, ACLListHandle_t **acllistp) tmpacllist = (ACLListHandle_t *)PR_HashTableLookup(hash, uri); if (tmpacllist != NULL) { if (tmpacllist != ACL_LIST_NO_ACLS) { - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); tmpacllist->ref_count++; /* we're going to use it */ } ACL_CritExit(); @@ -364,15 +364,15 @@ ACL_INTCacheEnter(int which, char *uri, ACLListHandle_t **acllistp) ACL_ListDestroy(errp, *acllistp); } *acllistp = tmpacllist; - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return; } /* Didn't find another list, so put ours in. */ /* Look for a matching ACL List and use it if we find one. */ if (*acllistp) { - NS_ASSERT(*acllistp != ACL_LIST_NO_ACLS); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(*acllistp != ACL_LIST_NO_ACLS); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); ACL_ListHashUpdate(acllistp); } else { *acllistp = ACL_LIST_NO_ACLS; @@ -380,7 +380,7 @@ ACL_INTCacheEnter(int which, char *uri, ACLListHandle_t **acllistp) PR_HashTableAdd(hash, pool_strdup((void **)acl_uri_hash_pool, uri), (void *)*acllistp); ACL_CritExit(); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return; } @@ -422,13 +422,13 @@ ACL_AddAclName(char *path, ACLListHandle_t **acllistp, ACLListHandle_t if (!acl) return; - NS_ASSERT(ACL_AssertAcl(acl)); + PR_ASSERT(ACL_AssertAcl(acl)); if (!*acllistp) *acllistp = ACL_ListNew(errp); ACL_ListAppend(NULL, *acllistp, acl, 0); - NS_ASSERT(ACL_AssertAcllist(*acllistp)); + PR_ASSERT(ACL_AssertAcllist(*acllistp)); return; } @@ -456,8 +456,8 @@ ACLListHandle_t *masterlist) int prefixlen; char *dst; - NS_ASSERT(path); - NS_ASSERT(prefix); + PR_ASSERT(path); + PR_ASSERT(prefix); dst = strncpy(ppath, prefix, ACL_PATH_MAX); if (dst >= (ppath+ACL_PATH_MAX-1)) { @@ -522,7 +522,7 @@ ACL_Init(void) ACL_InitAttr2Index(); ACLGlobal = (ACLGlobal_p)PERM_CALLOC(sizeof(ACLGlobal_s)); oldACLGlobal = (ACLGlobal_p)PERM_CALLOC(sizeof(ACLGlobal_s)); - NS_ASSERT(ACLGlobal && oldACLGlobal); + PR_ASSERT(ACLGlobal && oldACLGlobal); ACL_DATABASE_POOL = pool_create(); ACL_METHOD_POOL = pool_create(); ACL_CritInit(); diff --git a/lib/libaccess/aclerror.cpp b/lib/libaccess/aclerror.cpp index 2cbf2874..68395c72 100644 --- a/lib/libaccess/aclerror.cpp +++ b/lib/libaccess/aclerror.cpp @@ -17,7 +17,7 @@ #else #include "nspr/prprf.h" #endif -#include <base/nsassert.h> +#include "prlog.h" #include "libaccess/nserror.h" #include "libaccess/nsautherr.h" #include "libaccess/aclerror.h" @@ -110,7 +110,7 @@ void aclErrorFmt(NSErr_t * errp, char * msgbuf, int maxlen, int maxdepth) strncpy(msgbuf, efp->ef_errv[0], maxlen); break; default: - NS_ASSERT(0); /* don't break -- continue into case 0 */ + PR_ASSERT(0); /* don't break -- continue into case 0 */ case 0: switch (efp->ef_retcode) { case ACLERRFAIL: diff --git a/lib/libaccess/aclflush.cpp b/lib/libaccess/aclflush.cpp index dfee47d6..05fa18e4 100644 --- a/lib/libaccess/aclflush.cpp +++ b/lib/libaccess/aclflush.cpp @@ -7,7 +7,7 @@ * Source file for the ACL_CacheFlush-related routines. */ -#include <base/nsassert.h> +#include <prlog.h> #include <base/util.h> #include <libaccess/acl.h> #include "aclpriv.h" @@ -25,15 +25,15 @@ deletelists(PRHashEntry *he, PRIntn i, void *arg) ACLListHandle_t *acllist=(ACLListHandle_t *)he->value; NSErr_t *errp = 0; - NS_ASSERT(he); - NS_ASSERT(he->value); + PR_ASSERT(he); + PR_ASSERT(he->value); if (acllist->ref_count) { // If the list is in use, increment the counter. Then set the // stale flag. The other user can't delete the list since we're // counted as well. Finally, decrement the counter and whoever // sets it to zero will delete the ACL List. - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); acllist->ref_count++; acllist->flags |= ACL_LIST_STALE; if (--acllist->ref_count == 0) @@ -54,8 +54,8 @@ restartdeletelists(PRHashEntry *he, PRIntn i, void *arg) // what. ACLListHandle_t *acllist=(ACLListHandle_t *)he->value; - NS_ASSERT(he); - NS_ASSERT(he->value); + PR_ASSERT(he); + PR_ASSERT(he->value); ACL_ListDestroy(errp, acllist); @@ -67,7 +67,7 @@ static AclCacheFlushFunc_t AclCacheFlushRoutine = NULL; NSAPI_PUBLIC int ACL_CacheFlushRegister(AclCacheFlushFunc_t flush_func) { - NS_ASSERT(flush_func); + PR_ASSERT(flush_func); AclCacheFlushRoutine = flush_func; return 0; @@ -79,12 +79,12 @@ ACL_CacheFlush(void) ACLGlobal_p newACLGlobal; NSErr_t *errp = 0; - NS_ASSERT(ACLGlobal); - NS_ASSERT(ACLGlobal->masterlist); - NS_ASSERT(ACLGlobal->listhash); - NS_ASSERT(ACLGlobal->urihash); - NS_ASSERT(ACLGlobal->urigethash); - NS_ASSERT(ACLGlobal->pool); + PR_ASSERT(ACLGlobal); + PR_ASSERT(ACLGlobal->masterlist); + PR_ASSERT(ACLGlobal->listhash); + PR_ASSERT(ACLGlobal->urihash); + PR_ASSERT(ACLGlobal->urigethash); + PR_ASSERT(ACLGlobal->pool); ACL_CritEnter(); @@ -142,12 +142,12 @@ ACL_Restart(void *clntData) { NSErr_t *errp = 0; - NS_ASSERT(ACLGlobal); - NS_ASSERT(ACLGlobal->masterlist); - NS_ASSERT(ACLGlobal->listhash); - NS_ASSERT(ACLGlobal->urihash); - NS_ASSERT(ACLGlobal->urigethash); - NS_ASSERT(ACLGlobal->pool); + PR_ASSERT(ACLGlobal); + PR_ASSERT(ACLGlobal->masterlist); + PR_ASSERT(ACLGlobal->listhash); + PR_ASSERT(ACLGlobal->urihash); + PR_ASSERT(ACLGlobal->urigethash); + PR_ASSERT(ACLGlobal->pool); // Unlike ACL_CacheFlush, this routine can be much more cavalier about // freeing up memory, since there's guaranteed to be no users about at diff --git a/lib/libaccess/acltools.cpp b/lib/libaccess/acltools.cpp index 1283147e..9a9c820f 100644 --- a/lib/libaccess/acltools.cpp +++ b/lib/libaccess/acltools.cpp @@ -3384,9 +3384,9 @@ ACL_Decompose(NSErr_t *errp, char **acl, ACLListHandle_t *acl_list) /* * The following routines are used to validate input parameters. They always - * return 1, or cause an NS_ASSERT failure. The proper way to use them is - * with an NS_ASSERT in the calling function. E.g. - * NS_ASSERT(ACL_AssertAcllist(acllist)); + * return 1, or cause an PR_ASSERT failure. The proper way to use them is + * with an PR_ASSERT in the calling function. E.g. + * PR_ASSERT(ACL_AssertAcllist(acllist)); */ int @@ -3395,18 +3395,18 @@ ACL_AssertAcllist(ACLListHandle_t *acllist) ACLWrapper_t *wrap; if (acllist == ACL_LIST_NO_ACLS) return 1; - NS_ASSERT(acllist); - NS_ASSERT(acllist->acl_list_head); - NS_ASSERT(acllist->acl_list_tail); - NS_ASSERT(acllist->acl_count); - NS_ASSERT(acllist->ref_count > 0); + PR_ASSERT(acllist); + PR_ASSERT(acllist->acl_list_head); + PR_ASSERT(acllist->acl_list_tail); + PR_ASSERT(acllist->acl_count); + PR_ASSERT(acllist->ref_count > 0); for (wrap=acllist->acl_list_head; wrap; wrap=wrap->wrap_next) { - NS_ASSERT(ACL_AssertAcl(wrap->acl)); + PR_ASSERT(ACL_AssertAcl(wrap->acl)); } /* Artificially limit ACL lists to 10 ACLs for now */ - NS_ASSERT(acllist->acl_count < 10); + PR_ASSERT(acllist->acl_count < 10); return 1; } @@ -3414,11 +3414,11 @@ ACL_AssertAcllist(ACLListHandle_t *acllist) int ACL_AssertAcl(ACLHandle_t *acl) { - NS_ASSERT(acl); - NS_ASSERT(acl->ref_count); - NS_ASSERT(acl->expr_count); - NS_ASSERT(acl->expr_list_head); - NS_ASSERT(acl->expr_list_tail); + PR_ASSERT(acl); + PR_ASSERT(acl->ref_count); + PR_ASSERT(acl->expr_count); + PR_ASSERT(acl->expr_list_head); + PR_ASSERT(acl->expr_list_tail); return 1; } diff --git a/lib/libaccess/aclutil.cpp b/lib/libaccess/aclutil.cpp index 8d30fffb..add9a203 100644 --- a/lib/libaccess/aclutil.cpp +++ b/lib/libaccess/aclutil.cpp @@ -106,7 +106,7 @@ EvalToRes(int value) case LAS_EVAL_NEED_MORE_INFO: return ACL_RES_DENY; default: - NS_ASSERT(1); + PR_ASSERT(1); return ACL_RES_ERROR; } } diff --git a/lib/libaccess/avadb.c b/lib/libaccess/avadb.c index c0d98704..a2884082 100644 --- a/lib/libaccess/avadb.c +++ b/lib/libaccess/avadb.c @@ -11,8 +11,6 @@ #include "libaccess/avadb.h" #include "base/session.h" #include "base/pblock.h" -#include "frame/req.h" -#include "frame/log.h" #include "libadmin/libadmin.h" #include "libaccess/avapfile.h" diff --git a/lib/libaccess/oneeval.cpp b/lib/libaccess/oneeval.cpp index be837599..088940ff 100644 --- a/lib/libaccess/oneeval.cpp +++ b/lib/libaccess/oneeval.cpp @@ -19,7 +19,6 @@ #include <netsite.h> #include <base/systems.h> #include <base/crit.h> -#include <base/session.h> #include <libaccess/nserror.h> #include <libaccess/acl.h> #include "aclpriv.h" @@ -489,7 +488,7 @@ ACLEvalBuildContext( break; default: - NS_ASSERT(0); + PR_ASSERT(0); } /* switch expr_type */ @@ -683,14 +682,14 @@ ACL_INTEvalTestRights( rarray_p->acelist[rarray_p->count++] = (ACLAceNumEntry_t *)ACL_HashTableLookup_const(cache->Table, (char *)generic_rights[g_num]); - NS_ASSERT (rarray_p->count < ACL_MAX_GENERIC); + PR_ASSERT (rarray_p->count < ACL_MAX_GENERIC); } } } rights_cnt++; rights++; - NS_ASSERT (rights_cnt < ACL_MAX_TEST_RIGHTS); + PR_ASSERT (rights_cnt < ACL_MAX_TEST_RIGHTS); } /* Special case - look for an entry that applies to "all" rights */ @@ -974,10 +973,10 @@ ACL_EvalDestroy(NSErr_t *errp, pool_handle_t *pool, ACLEvalHandle_t *acleval) { if (!acleval->acllist || acleval->acllist == ACL_LIST_NO_ACLS) return; - NS_ASSERT(acleval->acllist->ref_count > 0); + PR_ASSERT(acleval->acllist->ref_count > 0); ACL_CritEnter(); - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); if (--acleval->acllist->ref_count == 0) { if (ACL_LIST_IS_STALE(acleval->acllist)) { ACL_ListDestroy(errp, acleval->acllist); @@ -1004,10 +1003,10 @@ ACL_ListDecrement(NSErr_t *errp, ACLListHandle_t *acllist) if (!acllist || acllist == ACL_LIST_NO_ACLS) return 0; - NS_ASSERT(ACL_AssertAcllist(acllist)); + PR_ASSERT(ACL_AssertAcllist(acllist)); ACL_CritEnter(); - NS_ASSERT(ACL_CritHeld()); + PR_ASSERT(ACL_CritHeld()); if (--acllist->ref_count == 0) { if (ACL_LIST_IS_STALE(acllist)) { ACL_ListDestroy(errp, acllist); @@ -1021,7 +1020,7 @@ ACL_ListDecrement(NSErr_t *errp, ACLListHandle_t *acllist) NSAPI_PUBLIC int ACL_EvalSetACL(NSErr_t *errp, ACLEvalHandle_t *acleval, ACLListHandle_t *acllist) { - NS_ASSERT(ACL_AssertAcllist(acllist)); + PR_ASSERT(ACL_AssertAcllist(acllist)); acleval->acllist = acllist; return(0); diff --git a/lib/libaccess/register.cpp b/lib/libaccess/register.cpp index 2973e1d5..22074d67 100644 --- a/lib/libaccess/register.cpp +++ b/lib/libaccess/register.cpp @@ -11,7 +11,7 @@ #include <plhash.h> #include <base/systems.h> #include <base/util.h> -#include <base/nsassert.h> +#include <prlog.h> #include "permhash.h" #include <libaccess/nserror.h> #include <libaccess/acl.h> @@ -48,7 +48,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLLasEvalHash); + PR_ASSERT(ACLLasEvalHash); ACLLasFlushHash = PR_NewHashTable(0, PR_HashString, @@ -56,7 +56,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLLasFlushHash); + PR_ASSERT(ACLLasFlushHash); ACLMethodHash = PR_NewHashTable(ACL_MAX_METHOD, PR_HashCaseString, @@ -64,7 +64,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLMethodHash); + PR_ASSERT(ACLMethodHash); ACLDbTypeHash = PR_NewHashTable(ACL_MAX_DBTYPE, PR_HashCaseString, @@ -72,7 +72,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLDbTypeHash); + PR_ASSERT(ACLDbTypeHash); for (i = 0; i < ACL_MAX_DBTYPE; i++) ACLDbParseFnTable[i] = 0; @@ -83,7 +83,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLDbTypeHash); + PR_ASSERT(ACLDbTypeHash); ACLDbNameHash = PR_NewHashTable(0, PR_HashCaseString, @@ -91,7 +91,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, ACL_DATABASE_POOL); - NS_ASSERT(ACLDbNameHash); + PR_ASSERT(ACLDbNameHash); ACLUserLdbHash = PR_NewHashTable(0, PR_HashCaseString, @@ -99,7 +99,7 @@ ACL_LasHashInit() PR_CompareValues, &ACLPermAllocOps, NULL); - NS_ASSERT(ACLUserLdbHash); + PR_ASSERT(ACLUserLdbHash); return; } @@ -166,7 +166,7 @@ NSAPI_PUBLIC int ACL_LasFindEval(NSErr_t *errp, char *attr_name, LASEvalFunc_t *eval_funcp) { - NS_ASSERT(attr_name); + PR_ASSERT(attr_name); if (!attr_name) return -1; *eval_funcp = (LASEvalFunc_t)PR_HashTableLookup(ACLLasEvalHash, attr_name); @@ -187,7 +187,7 @@ NSAPI_PUBLIC int ACL_LasFindFlush(NSErr_t *errp, char *attr_name, LASFlushFunc_t *flush_funcp) { - NS_ASSERT(attr_name); + PR_ASSERT(attr_name); if (!attr_name) return -1; *flush_funcp = (LASFlushFunc_t)PR_HashTableLookup(ACLLasFlushHash, attr_name); diff --git a/lib/libadmin/Makefile b/lib/libadmin/Makefile index a1904250..dac26ef4 100644 --- a/lib/libadmin/Makefile +++ b/lib/libadmin/Makefile @@ -22,14 +22,10 @@ else LIBS=$(OBJDIR)/lib/libadmin.a endif -OBJS=$(addprefix $(OBJDEST)/, admconf.o form_get.o error.o admlog.o \ - magconf.o ns-util.o objconf.o password.o \ - referer.o template.o util.o \ - hinstall.o admserv.o install.o nsnews.o \ - commit.o pcontrol.o get_msg.o \ - multconf.o httpcon.o authdb.o usrlists.o \ - dstats.o backup.o cluster.o \ - keyconf.o strlist.o $(OSOBJS)) +OBJS=$(addprefix $(OBJDEST)/, error.o \ + template.o util.o \ + authdb.o \ + strlist.o $(OSOBJS)) # moved files [to libadminutil] : form_post.o strlist.o distadm.o cron_conf.o # candidate for moing: admlog.o error.o admserv.o @@ -39,8 +35,8 @@ OBJS=$(addprefix $(OBJDEST)/, admconf.o form_get.o error.o admlog.o \ all: $(OBJDEST) $(LIBS) -$(LIBS): $(addprefix $(BUILD_ROOT)/include/libadmin/, \ - hadm_msgs.i la_msgs.i) +#$(LIBS): $(addprefix $(BUILD_ROOT)/include/libadmin/, \ +# hadm_msgs.i la_msgs.i) include $(BUILD_ROOT)/nsconfig.mk diff --git a/lib/libadmin/authdb.c b/lib/libadmin/authdb.c index 8aff4ca8..e111d567 100644 --- a/lib/libadmin/authdb.c +++ b/lib/libadmin/authdb.c @@ -12,196 +12,12 @@ * (blame Mike McCool for functions with an MLM) */ -#ifdef XP_UNIX -#include <dirent.h> -#endif /* WIN32? */ - #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include <stdio.h> -#include "base/shexp.h" -#include "base/util.h" -#include "libadminutil/admutil.h" -#include "libadmin/libadmin.h" - -#include "libaccess/nsgmgmt.h" -#include "libaccess/nsumgmt.h" -/* XXX MLM - This shouldn't have to define itself as private. */ -#define __PRIVATE_NSADB -#include "libaccess/nsadb.h" -#include "libaccess/nsamgmt.h" -#include "libaccess/aclerror.h" -#include "libaccess/aclbuild.h" -#include "libaccess/acladmin.h" -#include "usrlists.h" - -#define BUF_SIZE 10 - -void list_authdbs(char *fullpath, char *partialpath); - -static char **list; -static int listsize; -static int curentry; - -/* - * Rights we know about. This should be moved out to some - * external location. Perhaps obj.conf? - */ -NSAPI_PUBLIC char *acl_read_rights[] = -{ - "GET", - "HEAD", - "POST", - "INDEX", -#ifdef MCC_PROXY - "CONNECT", -#endif - NULL -}; - -NSAPI_PUBLIC char *acl_write_rights[] = -{ - "PUT", - "DELETE", - "MKDIR", - "RMDIR", - "MOVE", - NULL -}; - - -/* - * passfilter - function returns non-zero if the regular expression - * passed in matches the string passed in. - */ -static int passfilter(char *str, char *regexp) -{ - if (!str) - return 0; /* NULL string never matches */ - else if (!regexp) - return 1; /* NULL regexp matches everything */ - else - return(!shexp_casecmp(str, regexp)); -} - -NSAPI_PUBLIC char **list_auth_dbs(char *fullpath) -{ - list = new_strlist(BUF_SIZE); - listsize = BUF_SIZE; - curentry = 0; - list_authdbs(fullpath, ""); - - return(list); -} - -NSAPI_PUBLIC void output_authdb_selector(char *path, char *element, char *current) { - char **pathlist = list_auth_dbs(path); - int currentnum = -1; - int plen = path ? strlen(path) : 0; - register int x; - - /* - * If the 'current' string begins with the 'path' string, remove the - * 'path' prefix. - */ - if (!strncmp(current, path, plen)) { - current += plen; - if (*current == FILE_PATHSEP) ++current; - } - - if (pathlist[0]) /* Is there at least one database? */ - { - /* Find current selection in list of databases. */ - for(x=0; pathlist[x]; x++) { - if(!strcmp(current, pathlist[x])) { - currentnum = x; - continue; - } - } - -/* BONEHEAD */ - fprintf(stdout, "<SELECT name=\"%s\" %s>", - element, (x>SELECT_OVERFLOW) ? "size=5" : ""); - - /* If the current selection is in there, put it first. */ - if(currentnum != -1) { - fprintf(stdout, "<OPTION value=\"%s\" SELECTED>%s\n", - pathlist[currentnum], pathlist[currentnum]); - - } - for(x=0; pathlist[x]; x++) { - if (x == currentnum) - continue; - - fprintf(stdout, "<OPTION value=\"%s\">%s\n", - pathlist[x], pathlist[x]); - } - fprintf(stdout, "</SELECT>"); - } else { - fprintf(stdout, "<b>No databases found.</b>"); - } -} - -NSAPI_PUBLIC char *get_current_authdb() -{ - char **config = get_adm_config(); - return(STRDUP(config[3])); -} - -NSAPI_PUBLIC void set_current_authdb(char *current) -{ - char **config = get_adm_config(); - config[3] = STRDUP(current); - write_adm_config(config); -} - -void list_authdbs(char *fullpath, char *partialpath) -{ - int stat_good; - struct stat finfo; - char **dirlisting; - char *path = (char *)MALLOC(strlen(fullpath)+strlen(partialpath)+2); - - sprintf(path, "%s%c%s", fullpath, FILE_PATHSEP, partialpath); - if( !(dirlisting = list_directory(path,0))) - return; - else { - register int x; - char *entry, *newppath; - - for(x=0; dirlisting[x]; x++) { - entry = (char *)MALLOC(strlen(path)+strlen(dirlisting[x])+2); - sprintf(entry, "%s%s", path, dirlisting[x]); - -#ifdef XP_UNIX - stat_good = (lstat(entry, &finfo) == -1 ? 0 : 1); -#else /* WIN32 */ - stat_good = (stat(entry, &finfo) == -1 ? 0 : 1); -#endif /* XP_UNIX */ - - if(!stat_good) - continue; - newppath = (char *)MALLOC(strlen(partialpath)+strlen(dirlisting[x])+3); - - if(S_ISDIR(finfo.st_mode)) { - sprintf(newppath, "%s%s", partialpath, dirlisting[x]); - curentry++; - - if(!(curentry < listsize)) { - listsize += BUF_SIZE; - list = grow_strlist(list, listsize); - } - list[curentry-1] = STRDUP(newppath); - list[curentry] = NULL; - } - - FREE(entry); - FREE(newppath); - } - } -} +#include "netsite.h" /* Get the userdb directory. (V1.x) */ NSAPI_PUBLIC char *get_userdb_dir(void) @@ -221,2247 +37,3 @@ NSAPI_PUBLIC char *get_userdb_dir(void) userdb = STRDUP(line); return userdb; } - -/* Get the httpacl directory. (V2.x) */ -NSAPI_PUBLIC char *get_httpacl_dir(void) -{ - char *httpacl; - char line[BIG_LINE]; - -#ifdef USE_ADMSERV - char *tmp = getenv("NETSITE_ROOT"); - - sprintf(line, "%s%chttpacl", tmp, FILE_PATHSEP); -#else - char *tmp = get_mag_var("#ServerRoot"); - - sprintf(line, "%s%cadmin%chttpacl", tmp, FILE_PATHSEP, FILE_PATHSEP); -#endif - httpacl = STRDUP(line); - return httpacl; -} - -/* Get the authdb directory. (V2.x) */ -NSAPI_PUBLIC char *get_authdb_dir(void) -{ - char *authdb; - char line[BIG_LINE]; - -#ifdef USE_ADMSERV - char *tmp = getenv("NETSITE_ROOT"); - - sprintf(line, "%s%cauthdb", tmp, FILE_PATHSEP); -#else - char *tmp = get_mag_var("#ServerRoot"); - - sprintf(line, "%s%cadmin%cauthdb", tmp, FILE_PATHSEP, FILE_PATHSEP); -#endif - authdb = STRDUP(line); - return authdb; -} -/* - * groupOrUser - function sets its return variable flags - * based on whether the name passed in is - * a user or a group in the specified database. - * It could be both, although the entry form - * are intended to prohibit this. - * Returns: 0 if no error occurs, something else otherwise. - */ -NSAPI_PUBLIC int groupOrUser(char *db_path, char *name, int *is_user, int *is_group) -{ - int rv = 1; - UserObj_t *uoptr; - GroupObj_t *goptr; - void *padb; - - if (name && is_user && is_group) { - *is_user = 0; - *is_group = 0; - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (!rv) { - - rv = nsadbFindByName(NULL, padb, name, AIF_USER, (void **)&uoptr); - if (rv == AIF_USER) { - *is_user = 1; - } - - rv = nsadbFindByName(NULL, padb, name, AIF_GROUP, (void **)&goptr); - if (rv == AIF_GROUP) { - *is_group = 1; - } - - nsadbClose(padb, 0); - } - } - - return rv; -} - -/* - * getfullname - function to get the fullname of a user. - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int getfullname(char *db_path, char *user, char **fullname) { - int rv; - UserObj_t *uoptr; - void *padb; - - if (db_path && user) - { - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv == 0) { - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (rv == AIF_USER) { - *fullname = (uoptr->uo_rname != 0) ? STRDUP((char *)uoptr->uo_rname) - : STRDUP(""); - } - else - rv = 1; - nsadbClose(padb, 0); - } - } - else - rv = 1; - - return rv; -} - -/* - * setfullname - function to set the fullname for the specified user. - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int setfullname(char *db_path, char *user, char *fullname) { - int rv; - UserObj_t *uoptr; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to update " - "the user's fullname in the database."); - } else { - /* See if the user already exists, if so, update it. */ - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (rv == AIF_USER) { - uoptr->uo_rname = (NTS_t)fullname; - } else { - /* User doesn't exist, so we've failed. */ - report_error(SYSTEM_ERROR, user, - "Unable to change this user's fullname, " - "user was not found in the database."); - rv = 1; - } - - if (uoptr) { - rv = nsadbModifyUser(NULL, padb, uoptr); - if (rv < 0) - report_error(SYSTEM_ERROR, user, - "A database error occurred while " - "trying to change the user fullname."); - } - nsadbClose(padb, 0); - } - return rv; -} - -/* Set a user's login name MLM*/ -NSAPI_PUBLIC int setusername(char *db_path, char *user, char *newname) { - int rv; - UserObj_t *uoptr; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to update " - "the user's fullname in the database."); - } else { - /* See if the user already exists, if so, update it. */ - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (rv != AIF_USER) { - /* User doesn't exist, so we've failed. */ - report_error(SYSTEM_ERROR, user, - "Unable to change this user's fullname, " - "user was not found in the database."); - rv = 1; - } - if (uoptr) { - rv = userRename(NULL, ((AuthDB_t *)padb)->adb_userdb, - uoptr, (NTS_t)newname); - - if (rv < 0) - report_error(SYSTEM_ERROR, user, - "A database error occurred while " - "trying to change the login name."); - } - nsadbClose(padb, 0); - } - return rv; -} - -/* - * addusertogroup - function to add a user to a group - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int addusertogroup(char *db_path, char *user, char *group) { - int rv; - UserObj_t *uoptr; - GroupObj_t *goptr; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to add " - "user to a group."); - } else { - /* See if the user and group exist. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (goptr == 0) { - report_error(INCORRECT_USAGE, group, - "The group was not found."); - } - else if (uoptr == 0) { - report_error(INCORRECT_USAGE, user, - "The user was not found."); - } - else { - rv = nsadbAddUserToGroup(NULL, padb, goptr, uoptr); - } - - nsadbClose(padb, 0); - } - return rv; -} - -/* - * addgrouptogroup - function to add a group to a group - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int addgrouptogroup(char *db_path, char *memgroup, char *group) { - int rv; - GroupObj_t *goptr; - GroupObj_t *mem_goptr; - void *padb; - - if (!strcmp(memgroup, group)) { - report_error(INCORRECT_USAGE, group, - "You can't add a group to itself."); - } - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to add " - "group to a group."); - } else { - /* See if the groups exist. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - rv = nsadbFindByName(NULL, - padb, memgroup, AIF_GROUP, (void **)&mem_goptr); - if (goptr == 0) { - report_error(INCORRECT_USAGE, group, - "The target group was not found."); - } - else if (mem_goptr == 0) { - report_error(INCORRECT_USAGE, memgroup, - "The group to add was not found."); - } - else { - rv = nsadbAddGroupToGroup(NULL, padb, goptr, mem_goptr); - } - - nsadbClose(padb, 0); - } - return rv; -} - -/* - * remuserfromgroup - function to remove a user from a group - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int remuserfromgroup(char *db_path, char *user, char *group) { - int rv; - UserObj_t *uoptr; - GroupObj_t *goptr; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to add " - "user to a group."); - } else { - /* See if the user and group exist. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (goptr == 0) { - report_error(SYSTEM_ERROR, group, - "The group was not found."); - } - else if (uoptr == 0) { - report_error(SYSTEM_ERROR, user, - "The user was not found."); - } - else { - rv = nsadbRemUserFromGroup(NULL, padb, goptr, uoptr); - if (rv) - report_error(SYSTEM_ERROR, "Error taking out user", - "An error occured trying to take " - "the user out of the group."); - } - - nsadbClose(padb, 0); - } - return rv; -} - -/* - * remgroupfromgroup - function to remove a group to a group - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int remgroupfromgroup(char *db_path, char *memgroup, char *group) { - int rv; - GroupObj_t *goptr; - GroupObj_t *mem_goptr; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to remove " - "a group from a group."); - } else { - /* See if the groups exist. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - rv = nsadbFindByName(NULL, - padb, memgroup, AIF_GROUP, (void **)&mem_goptr); - if (goptr == 0) { - report_error(SYSTEM_ERROR, group, - "The target group was not found."); - } - else if (mem_goptr == 0) { - report_error(SYSTEM_ERROR, memgroup, - "The group to remove was not found."); - } - else { - rv = nsadbRemGroupFromGroup(NULL, padb, goptr, mem_goptr); - } - - nsadbClose(padb, 0); - } - return rv; -} - -/* - * setpw - function to set the password for the specified user. - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int setpw(char *db_path, char *user, char *pwd) { - int rv; - UserObj_t *uoptr = 0; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to add " - "the password to the database."); - } else { - /* See if the user already exists, if so, update it. */ - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (uoptr != 0) { - uoptr->uo_pwd = (NTS_t)STRDUP(pw_enc(pwd)); - } else { - /* User doesn't exist, so we've failed. */ - report_error(SYSTEM_ERROR, user, - "Unable to change this user's password, " - "user was not found in the database."); - rv = 1; - } - - if (uoptr) { - rv = nsadbModifyUser(NULL, padb, uoptr); - if (rv < 0) - report_error(SYSTEM_ERROR, user, - "A database error occurred while " - "trying to change the user password."); - } - nsadbClose(padb, 0); - } - return rv; -} - -/* - * setdbpw - function to set the password on the special user - * who's password is used as the database password. - * If the password passed in is NULL, the user is - * removed or not created. - * If the password is not NULL, then the user will - * be created if needed, and it's password set to - * the one passed in. - * - * Return: Returns 0 if it works, something else if it fails. - */ -NSAPI_PUBLIC int setdbpw(char *db_path, char *pwd) -{ - int rv; - UserObj_t *uoptr = 0; - void *padb; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Open Database", - "An error occurred while trying to add " - "the password to the database."); - } - /* - * If NULL pwd, remove the user if it exists. - */ - else if (pwd == NULL) { - rv = nsadbRemoveUser(NULL, padb, DBPW_USER); - nsadbClose(padb, 0); - - /* - * If we get success(0) or a no such user error(NSAERRNAME) - * we're happy. - */ - if (rv != 0 && rv != NSAERRNAME) { - report_error(SYSTEM_ERROR, "Remove Password Failed", - "An error occurred while trying to remove " - "the password for the database."); - } - } else { - /* See if the user already exists, if so, just update it. */ - rv = nsadbFindByName(NULL, padb, DBPW_USER, AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - /* User doesn't exist, so add it. */ - uoptr = userCreate((NTS_t)DBPW_USER, (NTS_t)pw_enc(pwd), (NTS_t)DBPW_USER); - if (uoptr == 0) { - report_error(SYSTEM_ERROR, "Failed To Update Database", - "An error occurred while trying to add " - "the password to the database."); - rv = 1; - } - else { - rv = nsadbCreateUser(NULL, padb, uoptr); - } - } else { - uoptr->uo_pwd = (NTS_t)STRDUP(pw_enc(pwd)); - rv = nsadbModifyUser(NULL, padb, uoptr); - } - - nsadbClose(padb, 0); - - if (uoptr) { - if (rv < 0) { - report_error(SYSTEM_ERROR, "Failed To Set Database Password", - "An error occurred while trying to save " - "the password in the database."); - rv = 1; - } - userFree(uoptr); - } - } - return rv; -} - -/* - * checkdbpw - Return TRUE if the password is correct, or database - * doesn't have one, because the password user isn't there. - * Return FALSE if required password is not correct. - */ -NSAPI_PUBLIC int checkdbpw(char *db_path, char *pwd) -{ - int rv; - UserObj_t *uoptr = 0; - void *padb; - int fpwOK = 0; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv == 0) { - rv = nsadbFindByName(NULL, padb, DBPW_USER, AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - fpwOK = 1; /* Password userid isn't there, so none required. */ - } else { - if (pwd == NULL) - fpwOK = 0; /* PW user exists, no pw passed in, return false. */ - else { - if (pw_cmp(pwd, (char *)uoptr->uo_pwd)) - fpwOK = 0; /* passwords are different, so return false. */ - else - fpwOK = 1; /* passwords are the same, so return true. */ - } - userFree(uoptr); - } - nsadbClose(padb, 0); - } - return fpwOK; -} - -/* - * Create a link to another CGI: - * val - value text on the link - * targ - name of the CGI to start - * arg - argument to pass to the CGI - */ -void output_cgi_link(char *val, char *trg, char *arg) -{ - char line[BIG_LINE]; - sprintf(line, "%s?%s", trg, arg); - printf("<a href=index?options+acss+%s target='options'>%s</a>", - util_uri_escape(NULL, line), val); -} - -/* - * groupEnumCB - callback function from libaccess group enumerator - */ -static int groupEnumCB (NSErr_t * errp, - void * padb, void *parg, GroupObj_t *goptr) -{ - if (goptr && goptr->go_name && strlen((char *)goptr->go_name)) - ulsAddToList(parg, goptr->go_gid, (char *)goptr->go_name); - - return 0; /* 0: continue enumeration */ -} - -/* - * userEnumCB - callback function from libaccess group enumerator - */ -static int userEnumCB (NSErr_t * errp, - void * padb, void *parg, UserObj_t *uoptr) -{ - if (uoptr && uoptr->uo_name && strlen((char *)uoptr->uo_name)) - ulsAddToList(parg, uoptr->uo_uid, (char *)uoptr->uo_name); - - return 0; /* 0: continue enumeration */ -} - -/* - * idfound - horribly inefficient scan through the idlist table - * returning true if the specified id is found, false - * otherwise. - */ -int idfound(int id, int *idlist, int count) -{ - int i; - for (i = 0; i < count; ++i) { - if (id == idlist[i]) - return 1; - } - return 0; -} - -void output_groups_user_is_in(char *db_path, char *user) -{ - int rv; - UserObj_t *uoptr = 0; - GroupObj_t *goptr = 0; - void *padb; - USI_t *gidlist; - int i; - int id; - char *group; - char *gname; - int groupCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list group membership."); - } else { - /* See if the user exists. */ - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - /* User doesn't exist, so we've failed. */ - report_error(SYSTEM_ERROR, user, - "Unable to find user when trying to " - "list group membership."); - rv = 1; - } else { - groupCount = UILCOUNT(&uoptr->uo_groups); - if (groupCount > 0) { - void *DirectlyInList; - void *IndirectlyInList; - ulsAlloc(&DirectlyInList); - ulsAlloc(&IndirectlyInList); - - gidlist = UILLIST(&uoptr->uo_groups); - for (i = 0; i < groupCount; ++i) { - rv = nsadbIdToName(NULL, - padb, gidlist[i], AIF_GROUP, &gname); - if (rv >= 0) { - rv = nsadbFindByName(NULL, padb, gname, AIF_GROUP, - (void **)&goptr); - } - if (goptr != 0) { - if (goptr->go_name && strlen((char *)goptr->go_name)) { - if (idfound(uoptr->uo_uid, - (int*)UILLIST(&goptr->go_users), - UILCOUNT(&goptr->go_users))) { - ulsAddToList(DirectlyInList, goptr->go_gid, - (char *)goptr->go_name); - } - else { - ulsAddToList(IndirectlyInList, goptr->go_gid, - (char *)goptr->go_name); - } - } - groupFree(goptr); - goptr = 0; - } - } - ulsSortName(DirectlyInList); - ulsGetCount(DirectlyInList, &groupCount); - for (i=0; i<groupCount; ++i) { - group = NULL; - ulsGetEntry(DirectlyInList, i, &id, &group); - if (group) { - printf("<tr><td>"); - printf("Member of <b>%s</b></td><td>", group); - sprintf(line, "group=%s", group); - output_cgi_link("Edit Group", "grped", line); - printf("</td><td>"); - sprintf(line, "remfromgrp_but=1&memuser=%s&group=%s", - user, group); - output_cgi_link("Remove from Group", "grped", line); - printf("</td>\n"); - } - } - ulsSortName(IndirectlyInList); - ulsGetCount(IndirectlyInList, &groupCount); - for (i=0; i<groupCount; ++i) { - group = NULL; - ulsGetEntry(IndirectlyInList, i, &id, &group); - if (group) { - printf("<tr><td>"); - printf("Indirect member of <b>%s</b></td><td>", group); - sprintf(line, "group=%s", group); - output_cgi_link("Edit Group", "grped", group); - printf("</td><td>"); - sprintf(line, "addtogrp_but=1&memuser=%s&group=%s", - user, group); - output_cgi_link("Add to Group", "grped", line); - printf("</td>\n"); - } - } - ulsFree(&DirectlyInList); - ulsFree(&IndirectlyInList); - } - } - } - return; -} - -/* - * output a table with the groups the user isn't a member of - */ -void output_nonmembership(char *db_path, char *user) -{ - int rv; - UserObj_t *uoptr = 0; - void *padb; - USI_t *gidlist; - int i; - int id; - char *group; - int groupCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list group membership."); - } else { - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - report_error(SYSTEM_ERROR, user, - "Unable to find user when trying to " - "list group membership."); - rv = 1; - } else { - void *sortList; - - ulsAlloc(&sortList); - rv = nsadbEnumerateGroups(NULL, padb, - (void *)sortList, groupEnumCB); - - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - - if (groupCount > 0) { - gidlist = UILLIST(&uoptr->uo_groups); - for (i=0; i<groupCount; ++i) { - group = NULL; - ulsGetEntry(sortList, i, &id, &group); - if (group && !idfound(id, (int*)gidlist, UILCOUNT(&uoptr->uo_groups))){ - printf("<tr><td>"); - printf("Not a member of <b>%s</b></td><td>", group); - sprintf(line, "group=%s", group); - output_cgi_link("Edit Group", "grped", line); - printf("</td><td>"); - sprintf(line, "addtogrp_but=1&memuser=%s&group=%s", - user, group); - output_cgi_link("Add to Group", "grped", line); - printf("</td>\n"); - } - } - } - ulsFree(&sortList); - userFree(uoptr); - } - } - return; -} - -/* - * output_group_membership - output a table showing which - * groups a user is in. - */ -void output_group_membership(char *db_path, char *user) -{ - printf("<table border=1><caption align=left>\n"); - printf("<b>%s group membership:</b>", user); - printf("</caption>\n"); - output_groups_user_is_in(db_path, user); - output_nonmembership(db_path, user); - printf("</table>\n"); -} - -void output_grpgroup_membership(char *db_path, char *group, char *filter) -{ - int rv; - GroupObj_t *goptr = 0; - void *padb; - USI_t *gidlist; - int i; - int id; - char *gname; - char *memgroup; - int groupCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list group membership."); - } else { - /* See if the group exists. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - /* Group doesn't exist, so we've failed. */ - report_error(SYSTEM_ERROR, group, - "Unable to find group when trying to " - "list group membership."); - rv = 1; - } else { - groupCount = UILCOUNT(&goptr->go_groups); - if (groupCount > 0) { - void *sortList; - ulsAlloc(&sortList); - - printf("<table border=1><caption align=left>\n"); - printf("<b>%s has these group members:</b>", group); - printf("</caption>\n"); - gidlist = UILLIST(&goptr->go_groups); - for (i = 0; i < groupCount; ++i) { - rv = nsadbIdToName(NULL, - padb, gidlist[i], AIF_GROUP, &gname); - if ((rv >= 0) && (gname != 0) && (strlen(gname) != 0)) { - ulsAddToList(sortList, gidlist[i], gname); - } - } - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - for (i=0; i<groupCount; ++i) { - memgroup = NULL; - ulsGetEntry(sortList, i, &id, &memgroup); - if (memgroup && passfilter(memgroup, filter)) { - printf("<tr><td>"); - printf("<b>%s</b></td><td>", memgroup); - sprintf(line, "group=%s", memgroup); - output_cgi_link("Edit Group", "grped", line); - printf("</td><td>"); - sprintf(line, "remfromgrp_but=1&memgroup=%s&group=%s", - memgroup, group); - output_cgi_link("Remove from Group", "grped", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - ulsFree(&sortList); - } else { - printf("<b>This group has no group members.</b>"); - } - groupFree(goptr); - } - nsadbClose(padb, 0); - } - return; -} - -/* - * Output a table showing the user members of a group. - */ -NSAPI_PUBLIC void output_user_membership(char *db_path, char *group, char *filter) -{ - int rv; - GroupObj_t *goptr = 0; - void *padb; - USI_t *uidlist; - char *user; - int i; - int id; - char *memuser; - int userCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list user membership."); - } else { - /* See if the group exists. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - /* Group doesn't exist, so we've failed. */ - nsadbClose(padb, 0); - report_error(SYSTEM_ERROR, group, - "Unable to find group when trying to " - "list user membership."); - rv = 1; - } else { - userCount = UILCOUNT(&goptr->go_users); - if (userCount > 0) { - void *sortList; - ulsAlloc(&sortList); - - printf("<table border=1><caption align=left>\n"); - printf("<b>%s has these user members:</b>", group); - printf("</caption>\n"); - uidlist = UILLIST(&goptr->go_users); - for (i = 0; i < userCount; ++i) { - rv = nsadbIdToName(NULL, - padb, uidlist[i], AIF_USER, &user); - if ((rv >= 0) && (user != 0) && (strlen(user) != 0)) { - ulsAddToList(sortList, uidlist[i], user); - } - } - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &userCount); - for (i=0; i<userCount; ++i) { - memuser = NULL; - ulsGetEntry(sortList, i, &id, &memuser); - if (memuser && passfilter(memuser, filter)) { - printf("<tr><td>"); - printf("<b>%s</b></td><td>", memuser); - sprintf(line, "user=%s", memuser); - output_cgi_link("Edit User", "usred", line); - printf("</td><td>"); - sprintf(line, "remfromgrp_but=1&memuser=%s&group=%s", - memuser, group); - output_cgi_link("Remove from Group", "grped", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - ulsFree(&sortList); - } else { - nsadbClose(padb, 0); - printf("<b>This group has no user members.</b>"); - } - } - } - return; -} - -/* - * Output a group showing all users. - */ -NSAPI_PUBLIC int output_users_list(char *db_path, char *filter) -{ - int rv; - void *padb; - int i; - int id; - char *user; - int userCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list users."); - else { - void *sortList; - - ulsAlloc(&sortList); - rv = nsadbEnumerateUsers(NULL, padb, (void *)sortList, userEnumCB); - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &userCount); - - if (userCount > 0) { - - printf("<table border=1><caption align=left>\n"); - printf("<b>User List:</b>"); - printf("</caption>\n"); - - for (i=0; i<userCount; ++i) { - user = NULL; - ulsGetEntry(sortList, i, &id, &user); - if (user && passfilter(user, filter)) { - printf("<tr><td>"); - printf("<b>%s</b></td><td>", user); - sprintf(line, "user=%s", user); - output_cgi_link("Edit User", "usred", line); - printf("</td><td>\n"); - output_cgi_link("Remove User", "usrrem", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - } else { - printf("<b>There are no users in the database.</b>"); - } - ulsFree(&sortList); - } - return rv; -} - -/* - * Output a table showing all groups. - */ -NSAPI_PUBLIC int output_groups_list(char *db_path, char *filter) -{ - int rv; - void *padb; - int i; - int id; - char *group; - int groupCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list groups."); - else { - void *sortList; - - ulsAlloc(&sortList); - rv = nsadbEnumerateGroups(NULL, padb, (void *)sortList, groupEnumCB); - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - - if (groupCount > 0) { - - printf("<table border=1><caption align=left>\n"); - printf("<b>Group List:</b>"); - printf("</caption>\n"); - - for (i=0; i<groupCount; ++i) { - group = NULL; - ulsGetEntry(sortList, i, &id, &group); - if ((group) && (passfilter(group, filter))) { - printf("<tr><td>"); - printf("<b>%s</b></td><td>", group); - sprintf(line, "group=%s", group); - output_cgi_link("Edit Group", "grped", line); - printf("</td><td>"); - output_cgi_link("Remove Group", "grprem", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - } else { - printf("<b>There are no groups in the database.</b>"); - } - ulsFree(&sortList); - } - return rv; -} - -/* Helper function: Return a uls list of all the groups a user is in. MLM */ -void *_list_user_groups(void *padb, char *user, int group_users) -{ - int rv; - register int i; - UserObj_t *uoptr = 0; - GroupObj_t *ugoptr = 0; - GroupObj_t *goptr = 0; - void *userGroupList = NULL; - int userGroupCount= 0; - USI_t *gidlist; - char *ugname = NULL; - - if(!group_users) { - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - } else { - rv = nsadbFindByName(NULL, padb, user, AIF_GROUP, (void **)&ugoptr); - } - if ((uoptr == 0) && (ugoptr == 0)) { - /* User doesn't exist, so we've failed. */ - return NULL; - } else { - if(uoptr) { - userGroupCount = UILCOUNT(&uoptr->uo_groups); - } else { - userGroupCount = UILCOUNT(&ugoptr->go_groups); - } - if (userGroupCount > 0) { - ulsAlloc(&userGroupList); - if(uoptr) { - gidlist = UILLIST(&uoptr->uo_groups); - } else { - gidlist = UILLIST(&ugoptr->go_groups); - } - - for (i = 0; i < userGroupCount; ++i) { - rv = nsadbIdToName(NULL, padb, - gidlist[i], AIF_GROUP, &ugname); - - if (rv >= 0) { - rv = nsadbFindByName(NULL, padb, ugname, AIF_GROUP, - (void **)&goptr); - } - if (goptr != 0) { - if (goptr->go_name && strlen((char *)goptr->go_name)) { - if(uoptr) { - if (idfound(uoptr->uo_uid, - (int*)UILLIST(&goptr->go_users), - UILCOUNT(&goptr->go_users))) { - ulsAddToList(userGroupList, goptr->go_gid, - (char *)goptr->go_name); - } - } else { - ulsAddToList(userGroupList, goptr->go_gid, - (char *)goptr->go_name); - } - } - groupFree(goptr); - goptr = 0; - } - } - } - } - return userGroupList; -} - -/* Output a selector box, with name "name", and make it a multiple - * selector box if multiple=1. */ -/* If user is non-null, then if it's a multiple selector, correctly highlight - * the groups the user is in. - * If group_user is 1, then the variable "user" refers to a *group* as - * a member, rather than a user. - * Highlight the item "highlight" regardless of membership (as long as - * it's non-NULL.) MLM */ -NSAPI_PUBLIC void output_group_selector(char *db_path, int group_user, - char *user, - char *highlight, char *except, - char *name, int none, int multiple) -{ - int rv; - void *padb; - int i, j, isselected; - int id; - char *group; - int groupCount; - void *userGroupList = NULL; - int userGroupCount= 0; - char *ugname = NULL; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list groups."); - else { - void *sortList; - - ulsAlloc(&sortList); - rv = nsadbEnumerateGroups(NULL, padb, (void *)sortList, groupEnumCB); - - if((multiple) && (user)) { - userGroupList=_list_user_groups(padb, user, group_user); - if(userGroupList) { - ulsSortName(userGroupList); - ulsGetCount(userGroupList, &userGroupCount); - } - } - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - - if (groupCount > 0) { - /* Make a pulldown if we can. If the size is bigger than the - * overflow value, make it a box to hack around the fact that - * the X Navigator can't scroll pulldown lists. */ - if((multiple) || (groupCount > SELECT_OVERFLOW)) { - printf("<SELECT size=5 name=%s %s>", - name, multiple? "MULTIPLE" : ""); - } else { - printf("<SELECT name=%s>", name); - } - if((!multiple) && (none)) { - printf("<OPTION value=NONE>NONE\n"); - } - - for (i=0; i<groupCount; ++i) { - group = NULL; - ugname = NULL; - isselected=0; - ulsGetEntry(sortList, i, &id, &group); - if (group) { - if((except) && (!strcmp(group, except))) - continue; - if((highlight) && (!strcmp(group, highlight))) - isselected=1; - if(userGroupList && !isselected) { - for(j=0; j < userGroupCount; j++) { - ulsGetEntry(userGroupList, j, &id, &ugname); -#if 0 - if(ugname[0] > group[0]) { - /* Both lists are sorted, therefore, if we've - * hit a letter that's after the group letter, - * it must not be here. */ - /* What can I say, it's a pathetic attempt - * on my part to mask the fact that I know - * this is inefficient. */ - break; - } -#endif - if(!strcmp(ugname, group)) { - isselected=1; - break; - } - } - } - printf("<OPTION %s>%s\n", - isselected? "SELECTED" : "", group); - } - } - printf("</SELECT>"); - } else { - printf("<b>(No groups have been created.)</b>"); - } - ulsFree(&sortList); - if(userGroupList) - ulsFree(&userGroupList); - } -} - -void *_list_group_users(void *padb, char *group, int group_users) -{ - int rv; - GroupObj_t *goptr = 0; - USI_t *uidlist; - char *user; - int i; - int userCount; - void *sortList=NULL; - - /* See if the group exists. */ - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - /* Group doesn't exist, so we've failed. */ - return NULL; - } else { - if(group_users) - userCount = UILCOUNT(&goptr->go_groups); - else - userCount = UILCOUNT(&goptr->go_users); - - if (userCount > 0) { - ulsAlloc(&sortList); - - if(group_users) - uidlist = UILLIST(&goptr->go_groups); - else - uidlist = UILLIST(&goptr->go_users); - - for (i = 0; i < userCount; ++i) { - if(group_users) - rv = nsadbIdToName(NULL,padb, uidlist[i], AIF_GROUP, &user); - else - rv = nsadbIdToName(NULL, padb, uidlist[i], AIF_USER, &user); - if ((rv >= 0) && (user != 0) && (strlen(user) != 0)) { - ulsAddToList(sortList, uidlist[i], user); - } - } - } - } - return sortList; -} - -/* - * Output a selector box of users. If group is non-null, highlight the - * users in that group. MLM - */ -NSAPI_PUBLIC void output_user_selector(char *db_path, char *group, - char *highlight, char *except, - char *name, int none, int multiple) -{ - int rv; - void *padb; - int i, j, isselected; - int id; - char *user; - int userCount; - void *groupUserList = NULL; - int groupUserCount= 0; - char *guname = NULL; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list groups."); - else { - void *sortList; - - ulsAlloc(&sortList); - rv = nsadbEnumerateUsers(NULL, padb, (void *)sortList, userEnumCB); - - if((multiple) && (group)) { - groupUserList=_list_group_users(padb, group, 0); - if(groupUserList) { - ulsSortName(groupUserList); - ulsGetCount(groupUserList, &groupUserCount); - } - } - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &userCount); - - if (userCount > 0) { - /* Make a pulldown if we can. If the size is bigger than the - * overflow value, make it a box to hack around the fact that - * the X Navigator can't scroll pulldown lists. */ - if((multiple) || (userCount > SELECT_OVERFLOW)) { - printf("<SELECT size=5 name=%s %s>", - name, multiple? "MULTIPLE" : ""); - } else { - printf("<SELECT name=%s>", name); - } - if((!multiple) && (none)) { - printf("<OPTION value=NONE>NONE\n"); - } - - for (i=0; i<userCount; ++i) { - user = NULL; - guname = NULL; - isselected=0; - ulsGetEntry(sortList, i, &id, &user); - if (user) { - if((except) && (!strcmp(user, except))) - continue; - if((highlight) && (!strcmp(user, highlight))) - isselected=1; - if(groupUserList && !isselected) { - for(j=0; j < groupUserCount; j++) { - ulsGetEntry(groupUserList, j, &id, &guname); -#if 0 - if(guname[0] > user[0]) { - /* Both lists are sorted, therefore, if we've - * hit a letter that's after the group letter, - * it must not be here. */ - /* What can I say, it's a pathetic attempt - * on my part to mask the fact that I know - * this is inefficient. */ - break; - } -#endif - if(!strcmp(guname, user)) { - isselected=1; - break; - } - } - } - printf("<OPTION %s>%s\n", - isselected? "SELECTED" : "", user); - } - } - printf("</SELECT>"); - } else { - printf("<b>(No users have been created.)</b>"); - } - ulsFree(&sortList); - if(groupUserList) - ulsFree(&groupUserList); - } -} - - -int _item_in_list(char *item, char **list) -{ - register int i; - if(!list) return -1; - for(i=0; list[i]; i++) { - if(!strcmp(list[i], item)) - return i; - } - return -1; -} - -/* Take a char ** null terminated list of group names, and change a user's - * memberships so those are the only groups he's in. MLM */ -NSAPI_PUBLIC void change_user_membership(char *db_path, char *user, - char **new_groups) -{ - void *sortList; - int rv; - void *padb; - UserObj_t *uoptr = NULL; - GroupObj_t *goptr = NULL; - int groupCount=0; - register int i; - int index; - int id; - char *group; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list groups."); - - sortList=_list_user_groups(padb, user, 0); - if(sortList) { - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - } - - rv = nsadbFindByName(NULL, padb, user, AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - report_error(INCORRECT_USAGE, user, "The user was not found."); - } - - /* First check the groups he's already in. Remove any that no longer - * appear in the list. */ - for(i=0; i<groupCount; ++i) { - ulsGetEntry(sortList, i, &id, &group); - - if( (index=_item_in_list(group, new_groups)) == -1) { - goptr=0; - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - report_error(INCORRECT_USAGE, group, - "The group was not found."); - } - rv = nsadbRemUserFromGroup(NULL, padb, goptr, uoptr); - } else { - /* This group is in the list, so mark it as taken care of. */ - if(new_groups) - new_groups[index][0]='\0'; - } - } - /* Add the user to any remaining groups. */ - if(new_groups) { - for(i=0; new_groups[i]; i++) { - if(new_groups[i][0] == '\0') - continue; - goptr=0; - rv = nsadbFindByName(NULL, padb, new_groups[i], - AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - report_error(INCORRECT_USAGE, group,"The group was not found."); - } - rv = nsadbAddUserToGroup(NULL, padb, goptr, uoptr); - } - } - - nsadbClose(padb, 0); -} - -/* Take a char ** null terminated list of user names, and change a group's - * memberships so those are the only users it has. MLM */ -/* Again, if group_users is 1, then the new_users are assumed to be groups. */ -NSAPI_PUBLIC void change_group_membership(char *db_path, char *group, - int group_users, char **new_users) -{ - void *sortList; - int rv; - void *padb; - UserObj_t *uoptr = NULL; - GroupObj_t *goptr = NULL; - GroupObj_t *ugoptr = NULL; - int userCount=0; - register int i; - int index; - int id; - char *user; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list groups."); - - sortList=_list_group_users(padb, group, group_users); - if(sortList) { - ulsSortName(sortList); - ulsGetCount(sortList, &userCount); - } - - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - report_error(INCORRECT_USAGE, group, "The group was not found."); - } - - /* First check the users already there. Remove any that no longer - * appear in the list. */ - for(i=0; i<userCount; ++i) { - ulsGetEntry(sortList, i, &id, &user); - if( (index=_item_in_list(user, new_users)) == -1) { - if(group_users) { - ugoptr=0; - rv = nsadbFindByName(NULL, padb, user, AIF_GROUP, - (void **)&ugoptr); - if (ugoptr == 0) { - report_error(INCORRECT_USAGE, user, - "The group was not found."); - } - rv = nsadbRemGroupFromGroup(NULL, padb, goptr, ugoptr); - } else { - uoptr=0; - rv = nsadbFindByName(NULL, padb, user, AIF_USER, - (void **)&uoptr); - if (uoptr == 0) { - report_error(INCORRECT_USAGE, user, - "The user was not found."); - } - rv = nsadbRemUserFromGroup(NULL, padb, goptr, uoptr); - } - } else { - /* This user is in the list, so mark it as taken care of. */ - if(new_users) - new_users[index][0]='\0'; - } - } - /* Add any remaining users. */ - if(new_users) { - for(i=0; new_users[i]; i++) { - if(new_users[i][0] == '\0') - continue; - if(group_users) { - ugoptr=0; - rv = nsadbFindByName(NULL, padb, new_users[i], - AIF_GROUP, (void **)&ugoptr); - if (ugoptr == 0) { - report_error(INCORRECT_USAGE, new_users[i], - "The group was not found."); - } - rv = nsadbAddGroupToGroup(NULL, padb, goptr, ugoptr); - if(rv) report_error(SYSTEM_ERROR, new_users[i], - "Unable to add group to group"); - } else { - uoptr=0; - rv = nsadbFindByName(NULL, padb, new_users[i], - AIF_USER, (void **)&uoptr); - if (uoptr == 0) { - report_error(INCORRECT_USAGE, new_users[i], - "The user was not found."); - } - rv = nsadbAddUserToGroup(NULL, padb, goptr, uoptr); - if(rv) report_error(SYSTEM_ERROR, new_users[i], - "Unable to add user to group"); - } - } - } - - nsadbClose(padb, 0); -} - -/* - * output a table with the groups that aren't members of the group - */ -NSAPI_PUBLIC void output_nongrpgroup_membership(char *db_path, char *group, char *filter) -{ - int rv; - GroupObj_t *goptr = 0; - void *padb; - USI_t *gidlist; - int i; - int id; - char *memgroup; - int groupCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list group membership."); - } else { - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - report_error(SYSTEM_ERROR, group, - "Unable to find group when trying to " - "list group membership."); - rv = 1; - nsadbClose(padb, 0); - } else { - void *sortList; - - printf("<table border=1><caption align=left>\n"); - printf("<b>These groups are not members of %s:</b>", group); - printf("</caption>\n"); - - ulsAlloc(&sortList); - rv = nsadbEnumerateGroups(NULL, - padb, (void *)sortList, groupEnumCB); - nsadbClose(padb, 0); - ulsSortName(sortList); - ulsGetCount(sortList, &groupCount); - - if (groupCount > 0) { - gidlist = UILLIST(&goptr->go_groups); - for (i=0; i<groupCount; ++i) { - memgroup = NULL; - ulsGetEntry(sortList, i, &id, &memgroup); - if ( memgroup && - strcmp(memgroup, group) && - !idfound(id, (int*)gidlist, UILCOUNT(&goptr->go_groups)) && - passfilter(memgroup, filter)) { - printf("<tr>"); - printf("<td><b>%s</b></td><td>", memgroup); - sprintf(line, "group=%s", memgroup); - output_cgi_link("Edit Group", "grped", line); - printf("</td><td>"); - sprintf(line, "addtogrp_but=1&memgroup=%s&group=%s", - memgroup, group); - output_cgi_link("Add to Group", "grped", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - } - ulsFree(&sortList); - groupFree(goptr); - } - } - return; -} - -/* - * output a table with the users that aren't members of the group - */ -NSAPI_PUBLIC void output_nonuser_membership(char *db_path, char *group, char *filter) -{ - int rv; - GroupObj_t *goptr = 0; - void *padb; - USI_t *gidlist; - int i; - int id; - char *memuser; - int userCount; - char line[BIG_LINE]; - - rv = nsadbOpen(NULL, db_path, 0, &padb); - if (rv < 0) { - report_error(SYSTEM_ERROR, db_path, - "Failed to open database while trying " - "to list group membership."); - } else { - rv = nsadbFindByName(NULL, padb, group, AIF_GROUP, (void **)&goptr); - if (goptr == 0) { - nsadbClose(padb, 0); - report_error(SYSTEM_ERROR, group, - "Unable to find group when trying to " - "list user membership."); - rv = 1; - } else { - void *sortList; - - printf("<table border=1><caption align=left>\n"); - printf("<b>These users are not members of %s:</b>", group); - printf("</caption>\n"); - - ulsAlloc(&sortList); - rv = nsadbEnumerateUsers(NULL, padb, (void *)sortList, userEnumCB); - nsadbClose(padb, 0); - - ulsSortName(sortList); - ulsGetCount(sortList, &userCount); - - if (userCount > 0) { - gidlist = UILLIST(&goptr->go_users); - for (i=0; i<userCount; ++i) { - memuser = NULL; - ulsGetEntry(sortList, i, &id, &memuser); - if ( memuser && - !idfound(id, (int*)gidlist, UILCOUNT(&goptr->go_users)) && - passfilter(memuser, filter)) { - printf("<tr>"); - printf("<td><b>%s</b></td><td>", memuser); - sprintf(line, "memuser=%s", memuser); - output_cgi_link("Edit User", "usred", line); - printf("</td><td>"); - sprintf(line, "addtogrp_but=1&memuser=%s&group=%s", - memuser, group); - output_cgi_link("Add to Group", "grped", line); - printf("</td>\n"); - } - } - printf("</table>\n"); - } - ulsFree(&sortList); - groupFree(goptr); - } - } - return; -} - -NSAPI_PUBLIC char *get_acl_file() -{ - char line[BIG_LINE]; - char *acl_file = get_mag_var("ACLFile"); - if (!acl_file) { - sprintf(line, "%s%cgenerated.%s.acl", - get_httpacl_dir(), FILE_PATHSEP, get_srvname(0)); - set_mag_var("ACLFile", line); - acl_file = STRDUP(line); - } - if(!file_exists(acl_file)) { - FILE *f; - if(! (f=fopen(acl_file, "w")) ) - report_error(FILE_ERROR, acl_file, "Could not open file."); - fclose(f); - } - return acl_file; -} - -NSAPI_PUBLIC char *get_workacl_file() -{ - char line[BIG_LINE]; - char *workacl_file; - sprintf(line, "%s%cgenwork.%s.acl", - get_httpacl_dir(), FILE_PATHSEP, get_srvname(0)); - workacl_file = STRDUP(line); - - if(!file_exists(workacl_file)) { - FILE *f; - char *current=get_acl_file(); - if(file_exists(current)) { - cp_file(current, workacl_file, 0644); - } else { - if(! (f=fopen(workacl_file, "w")) ) - report_error(FILE_ERROR, workacl_file, "Could not open file."); - fclose(f); - } - } - return workacl_file; -} - -/* - * get_acl_info - Open the specified ACL file. Return a context - * handle into it, the data it contains, and whether this is - * a default allow or default deny resource. - * - * Returns: 0 if it works - * AUTHDB_ACL_FAIL (-1) if it fails - * AUTHDB_ACL_ODD_ACL (-2) if the ACL doesn't appear to be one - * generated by the CGI. - */ -NSAPI_PUBLIC int get_acl_info(char *acl_file, char *acl_name, void **pacl, - char ***hosts, authInfo_t **authinfo, - char ***users, char ***userhosts, - int *fdefaultallow) -{ - int rv = 0; - char *acl_sig = NULL; - ACContext_t *acl_con = NULL; - ACL_t *acl; - - if (hosts) - *hosts = NULL; - if (authinfo) - *authinfo = NULL; - if (users) - *users = NULL; - if (userhosts) - *userhosts = NULL; - if (fdefaultallow) - *fdefaultallow = 0; - - if ((rv = accReadFile(NULL, acl_file, &acl_con))) - rv = AUTHDB_ACL_FAIL; - else if (!(rv = aclFindByName(acl_con, acl_name, NULL, 0, &acl))) - rv = AUTHDB_ACL_NOT_FOUND; - else { - /* - * If we get the ACL open, get it's signiture to see if - * it looks like one of ours. Each directive is identified - * by a single character in the signiture string. The ones - * we care about are: - * 'a' - default allow - * 'd' - default deny - * 'r' - default authenticate - * - * The ACL used for default allow access has these directives: - * default allow anyone at *; (required, shows up as an 'a') - * default deny anyone at (hosts); (optional, shows up as a 'd') - * - * The ACL used for default deny access has these directives: - * default deny anyone at *; (required, shows up as an 'd') - * default allow anyone at (hosts); (optional, shows up as a 'a') - * default authenticate... (optional, shows up as an 'r') - * default allow (users) at (hosts); (optional, shows up as a 'a') - * - * Valid signitures are: - * "a" - * "ad" - * "d" - * "da" - * "dra" - * "dara" - */ - - if (acl) - acl_sig = aclGetSignature(acl); - - if (acl_sig) { - if (!strcmp(acl_sig, "a")) { - if (fdefaultallow) - *fdefaultallow = 1; - rv = 0; - } - else if (!strcmp(acl_sig, "ad")) { - if (fdefaultallow) - *fdefaultallow = 1; - if (hosts) - *hosts = aclGetHosts(acl, 2, 1); - rv = 0; - } - else if (!strcmp(acl_sig, "d")) { - if (fdefaultallow) - *fdefaultallow = 0; - rv = 0; - } - else if (!strcmp(acl_sig, "da")) { - if (fdefaultallow) - *fdefaultallow = 0; - if (hosts) - *hosts = aclGetHosts(acl, 2, 1); - rv = 0; - } - else if (!strcmp(acl_sig, "dra")) { - if (fdefaultallow) - *fdefaultallow = 0; - if (authinfo) { - char *p; - *authinfo = (authInfo_t *)MALLOC(sizeof(authInfo_t)); - memset(*authinfo, 0, (sizeof(authInfo_t))); - if ((p = aclGetAuthMethod(acl, 2))) - (*authinfo)->type = strdup(p); - if ((p = aclGetDatabase(acl, 2))) - (*authinfo)->db_path = strdup(p); - if ((p = aclGetPrompt(acl, 2))) - (*authinfo)->prompt = strdup(p); - } - if (users) - *users = aclGetUsers(acl, 3, 1); - if (userhosts) - *userhosts = aclGetHosts(acl, 3, 1); - rv = 0; - } - else if (!strcmp(acl_sig, "dara")) { - if (fdefaultallow) - *fdefaultallow = 0; - if (hosts) - *hosts = aclGetHosts(acl, 2, 1); - if (authinfo) { - char *p; - *authinfo = (authInfo_t *)MALLOC(sizeof(authInfo_t)); - memset(*authinfo, 0, (sizeof(authInfo_t))); - if ((p = aclGetAuthMethod(acl, 3))) - (*authinfo)->type = strdup(p); - if ((p = aclGetDatabase(acl, 3))) - (*authinfo)->db_path = strdup(p); - if ((p = aclGetPrompt(acl, 3))) - (*authinfo)->prompt = strdup(p); - } - if (users) - *users = aclGetUsers(acl, 4, 1); - if (userhosts) - *userhosts = aclGetHosts(acl, 4, 1); - rv = 0; - } - else - rv = AUTHDB_ACL_ODD_ACL; - } - if (pacl) - *pacl = (void *)acl_con; - } - return rv; -} - - -static void add_acl_rights(ACContext_t *acc) -{ - int rv; - char **p; - for (p = acl_read_rights; *p; ++p) { - rv = aclRightDef(NULL, acc, *p, NULL); - } - for (p = acl_write_rights; *p; ++p) { - rv = aclRightDef(NULL, acc, *p, NULL); - } -} - -/* - * delete_acl_by_name - remove a specified acl. - * - * Return: 0 if it deletes an ACL. Otherwise something else. - * - */ -NSAPI_PUBLIC int delete_acl_by_name(char *acl_file, char *acl_name) -{ - int rv = 1; - ACContext_t *acl_con = NULL; - ACL_t *acl = NULL; - - if (acl_file && acl_name) - { - rv = accReadFile(NULL, acl_file, &acl_con); - - if (!rv) { - rv = aclFindByName(acl_con, acl_name, NULL, 0, &acl); - if (rv == 1 && acl) { - aclDelete(acl); - rv = accWriteFile(acl_con, acl_file, 0); - set_commit(0, 1); - } - } - } - return rv; -} - -/* - * set_acl_info - Replaces the specified ACL with the information - * provided. The fdefaultallow is tells us whether - * to generate a default allow everyone type ACL, or - * a default deny everyone type ACL. - * - * If opening the ACL file fails with a file open - * type error, it is assumed to not exist, and a - * new one is created. - * - * Returns: 0 if it works - * AUTHDB_ACL_FAIL if it fails - */ -NSAPI_PUBLIC int set_acl_info(char *acl_file, char *acl_name, int prefix, - void **pacl, char **rights, - char **hosts, authInfo_t *authinfo, - char **users, char **userhosts, - int fdefaultallow) -{ - int rv = AUTHDB_ACL_FAIL; - ACContext_t *acl_con = NULL; - ACL_t *acl = NULL; - int amethod = AUTH_METHOD_BASIC; - char *db_path = NULL; - char *prompt = NULL; - - /* - * Digest parms - */ - if (authinfo) { - if (!strcmp(authinfo->type, "SSL")) - amethod = AUTH_METHOD_SSL; - else - amethod = AUTH_METHOD_BASIC; - db_path = authinfo->db_path; - prompt = authinfo->prompt; - } - - if (prefix) - prefix = ACLF_NPREFIX; - else - prefix = 0; - - /* - * Open the specified ACL file, destroy the existing ACL with - * the specified name if it exists, and then write the new - * stuff back out. - */ - if (acl_file && acl_name) - { - (void)delete_acl_by_name(acl_file, acl_name); - rv = accReadFile(NULL, acl_file, &acl_con); - - /* - * If the file isn't there, create an empty context. - */ - if (rv == ACLERROPEN) - rv = accCreate(0, 0, &acl_con); - - if (rv) - rv = AUTHDB_ACL_FAIL; - else { - (void)add_acl_rights(acl_con); - - if (aclMakeNew(acl_con, "", acl_name, - rights, prefix, &acl)) { - rv = AUTHDB_ACL_FAIL; - } - else if (aclPutAllowDeny( - NULL, acl, 0, fdefaultallow, NULL, NULL)) { - rv = AUTHDB_ACL_FAIL; - } - else if (hosts && - (rv = aclPutAllowDeny( - NULL, acl, 0, !fdefaultallow, NULL, hosts))) { - - rv = AUTHDB_ACL_FAIL; - } - else if (users && authinfo && - ((rv = aclPutAuth(NULL, acl, 0, amethod, db_path, prompt))|| - (rv = aclPutAllowDeny(NULL, acl, 0, !fdefaultallow, - users, userhosts)))) { - - rv = AUTHDB_ACL_FAIL; - } - else { - if (accWriteFile(acl_con, acl_file, 0)) { - rv = AUTHDB_ACL_FAIL; - } - else { - set_commit(0, 1); - rv = 0; - if (pacl) - *pacl = (void *)acl; - } - } - } - } - return rv; -} - -/* - * get_acl_names - Passes back the names of the read and write - * ACLs for the current resource. - * The directive parm is usually "acl", but is - * also used to find stashed items under names - * like "acl-disabled". - * Returns 0 if no other ACLs are found, 1 if an ACL that - * doesn't match the type of name we generate. - */ -NSAPI_PUBLIC int get_acl_names(char **readaclname, char **writeaclname, char *directive) -{ - pblock **pbs; - char *aclname; - int fother_acls = 0; - char **config = get_adm_config(); - char *curres = get_current_resource(config); - int rtype = get_current_restype(config); - int i; - - *readaclname = NULL; - *writeaclname = NULL; - - pbs = list_pblocks(rtype, curres, "PathCheck", CHECK_ACL_FN); - - if (pbs) { - for (i=0; pbs[i]; ++i) { - aclname = pblock_findval(directive, pbs[i]); - if (is_readacl(aclname)) - *readaclname = strdup(aclname); - else if (is_writeacl(aclname)) - *writeaclname = strdup(aclname); - else - fother_acls = 1; - } - } - return fother_acls; -} - -NSAPI_PUBLIC int is_readacl(char *name) { - if (name) - return strstr(name, ACLNAME_READ_COOKIE)?1:0; - else - return 0; -} - -NSAPI_PUBLIC int is_writeacl(char *name) { - if (name) - return strstr(name, ACLNAME_WRITE_COOKIE)?1:0; - else - return 0; -} - -NSAPI_PUBLIC int admin_is_ipaddr(char *p) -{ - int i; - int num_found = 0; - - if (!p || !p[0]) - return 0; /* NULL isn't an IP Address */ - else { - for (i=0; p[i]; ++i) { - if (isalpha(p[i])) - return 0; /* If it has an alpha character, it's not IP addr */ - else if (isdigit(p[i])) { - num_found = 1; - } - } - } - /* - * Well, hard to say what it is, but if there's at least a number - * in it, and the ip number checker can parse it, we'll call it - * an IP address; - */ - if (num_found && get_ip_and_mask(p)) - return 1; - else - return 0; -} - -/* - * Get the hostnames and ipaddrs strings from the single hosts array - * of string pointers. - */ -NSAPI_PUBLIC void get_hostnames_and_ipaddrs(char **hosts, char **hostnames, char **ipaddrs) -{ - char *p; - int nbipaddrs = 0; - int nbhostnames = 0; - int i; - if (hosts && hostnames && ipaddrs) { - *hostnames = NULL; - *ipaddrs = NULL; - /* - * Make two passes, once to total the size needed for - * the hosts and ipaddrs string, then alloc them and - * strcat the strings in. - */ - for(i=0, p=hosts[i]; p; p=hosts[++i]) { - if (admin_is_ipaddr(p)) - nbipaddrs += strlen(p) + 2; /* Teminator and "," */ - else - nbhostnames += strlen(p) + 2; - } - - if (nbhostnames) { - *hostnames = (char *)MALLOC(nbhostnames + 1); - memset(*hostnames, 0, nbhostnames); - } - if (nbipaddrs) { - *ipaddrs = (char *)MALLOC(nbipaddrs + 1); - memset(*ipaddrs, 0, nbipaddrs); - } - - /* - * We've got the space, now go look at each, strcat it - * into the correct string, prefixed with a "," for all - * but the first. - */ - for(i=0, p=hosts[i]; p; p=hosts[++i]) { - if (admin_is_ipaddr(p)) { - if (strlen(*ipaddrs)) - strcat(*ipaddrs, ","); - strcat(*ipaddrs, p); - } - else { - if (strlen(*hostnames)) - strcat(*hostnames, ","); - strcat(*hostnames, p); - } - } - } - return; -} - -/* - * Get the usernames and groups strings from the single users array - * of string pointers. - */ -NSAPI_PUBLIC void get_users_and_groups(char **users, char **usernames, char **groups, - char *db_path) -{ - char *p; - int nbusernames = 0; - int nbgroups = 0; - int i; - int is_user = 0; - int is_group = 0; - - if (users && usernames && groups) { - *usernames = NULL; - *groups = NULL; - /* - * Make two passes, once to total the size needed for - * the strings, then alloc them and strcat the strings in. - */ - for(i=0, p=users[i]; p; p=users[++i]) { - is_user = 0; - is_group = 0; - groupOrUser(db_path, p, &is_user, &is_group); - - /* Enclose user/group name in quotes if necessary */ - p = aclSafeIdent(p); - - if (is_user) - nbusernames += strlen(p) + 2; /* Teminator and "," */ - else if (is_group) - nbgroups += strlen(p) + 2; - } - - if (nbusernames) { - *usernames = (char *)MALLOC(nbusernames + 1); - memset(*usernames, 0, nbusernames); - } - if (nbgroups) { - *groups = (char *)MALLOC(nbgroups + 1); - memset(*groups, 0, nbgroups); - } - - /* - * We've got the space, now go look at each, strcat it - * into the correct string, prefixed with a "," for all - * but the first. - */ - for(i=0, p=users[i]; p; p=users[++i]) { - is_user = 0; - is_group = 0; - groupOrUser(db_path, p, &is_user, &is_group); - - /* Enclose user/group name in quotes if necessary */ - p = aclSafeIdent(p); - - if (is_user) { - if (strlen(*usernames)) - strcat(*usernames, ","); - strcat(*usernames, p); - } - else if (is_group) { - if (strlen(*groups)) - strcat(*groups, ","); - strcat(*groups, p); - } - } - } - return; -} - -/* - * Load from host and IP Addr strings into the array of - * pointers to strings. - */ -NSAPI_PUBLIC void load_host_array(char ***hosts, char *hostnames, char *ipaddrs) -{ - char *tok; - int nMax = 20; - int nCur = 0; - char **hostarr; - char *valid_ip; - - if (hosts) { - hostarr = new_strlist(nMax); - hostarr[0] = NULL; - if (hostnames) { - for (tok = strtok(hostnames, ","); - tok; - tok = strtok(NULL, ",")) - { - if (!(nCur < nMax)) { - nMax += 20; - hostarr = grow_strlist(hostarr, nMax); - } - hostarr[nCur] = strdup(tok); - hostarr[++nCur] = NULL; - } - } - if (ipaddrs) { - for (tok = strtok(ipaddrs, ","); - tok; - tok = strtok(NULL, ",")) - { - if (!(nCur < nMax)) { - nMax += 20; - hostarr = grow_strlist(hostarr, nMax); - } - valid_ip = get_ip_and_mask(tok); - if (valid_ip) { - hostarr[nCur] = strdup(valid_ip); - hostarr[++nCur] = NULL; - } - } - } - *hosts = hostarr; - } - - return; -} - -void load_users_array(char ***users, char *usernames, char *groups) -{ - char *tok; - int nMax = 20; - int nCur = 0; - char **userarr; - - if (users) { - userarr = new_strlist(nMax); - userarr[0] = NULL; - if (usernames) { - for (tok = strtok(usernames, ","); - tok; - tok = strtok(NULL, ",")) - { - if (!(nCur < nMax)) { - nMax += 20; - userarr = grow_strlist(userarr, nMax); - } - userarr[nCur] = strdup(tok); - userarr[++nCur] = NULL; - } - } - if (groups) { - for (tok = strtok(groups, ","); - tok; - tok = strtok(NULL, ",")) - { - if (!(nCur < nMax)) { - nMax += 20; - userarr = grow_strlist(userarr, nMax); - } - userarr[nCur] = strdup(tok); - userarr[++nCur] = NULL; - } - } - *users = userarr; - } - - return; -} - -/* Removes enclosing double quotes from a string (in place) */ -NSAPI_PUBLIC char * str_unquote(char * str) -{ - if (str) { - if (str[0] == '"') { - int len = strlen(str); - - if (str[len-1] == '"') { - str[len-1] = 0; - ++str; - } - } - } - - return str; -} diff --git a/lib/libadmin/error.c b/lib/libadmin/error.c index a4f87842..2c3d740c 100644 --- a/lib/libadmin/error.c +++ b/lib/libadmin/error.c @@ -10,9 +10,6 @@ */ #include "libadmin/libadmin.h" -#if 0 -#include "cgiutils/cgi-util.h" -#endif #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,6 +17,7 @@ #include <windows.h> #include "base/nterr.h" #endif +#include <base/file.h> #define ERROR_HTML "error.html" @@ -57,7 +55,7 @@ void _report_error(int type, char *info, char *details, int shouldexit) /* Be sure headers are terminated. */ fputs("\n", stdout); - fprintf(stdout, "<SCRIPT LANGUAGE=\"%s\">", MOCHA_NAME); + fprintf(stdout, "<SCRIPT LANGUAGE=\"JavaScript\">"); output_alert(type, info, details, 0); if(shouldexit) { fprintf(stdout, "if(history.length>1) history.back();"); diff --git a/lib/libadmin/template.c b/lib/libadmin/template.c index a689d3b5..71e576cb 100644 --- a/lib/libadmin/template.c +++ b/lib/libadmin/template.c @@ -12,560 +12,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "template.h" #include "libadmin/libadmin.h" -#include "libadmin/dbtlibadmin.h" -#include "base/util.h" - -/* If you add something to this structure, don't forget to document it - * in templates.h, and increase MAXTEMPLATE! - * - * Also, save yourself a lot of grief and put a space after the name. - */ - -static struct template_s templates[MAXTEMPLATE] = { - {"IF ", "FUNC conditional"}, - {"ELSE ", "FUNC conditional"}, - {"ENDIF ", "FUNC conditional"}, - {"TITLE ", "<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n" - "<BODY bgcolor=\"#C0C0C0\" link=\"#0000EE\" " - "vlink=\"#551A8B\" alink=\"#FF0000\" %s>\n"}, - {"PAGEHEADER ", "FUNC pageheader"}, - {"DOCSWITCHER ", ""}, - {"COPYRIGHT ", ""}, - {"RESOURCEPICKER ", "FUNC respicker"}, - {"BOOKTRACK ", "FUNC booktrack"}, - {"BEGININFO ", "<table border=2 width=100%% cellpadding=2>\n" - "<tr><td align=center colspan=2>" - "<b><FONT size=+1>%s</FONT></b></td></tr>" -#if 0 - "<tr><td>" - "<IMG src=\"../icons/b-open.gif\" hspace=8 alt=\"*\"" - "height=26 width=55></td>" - "<td>\n"}, -#endif - "<td colspan=2>\n"}, - {"ADDINFO ", "</td></tr><tr><td colspan=2>"}, - {"ENDINFO ", "</td></tr></table>\n<hr width=10%%>\n"}, - {"SUBMIT ", "FUNC submit\n"}, - {"DOCUMENTROOT ", "FUNC docroot"}, - {"BEGINELEM ", "<pre>"}, -/* {"ELEM ", "<hr width=100%%><b>%s</b>"}, */ - {"ELEM ", "\n<b>%s</b>"}, -/* {"ENDELEM ", "<hr width=100%%></pre>\n"}, */ - {"ENDELEM ", "</pre>\n"}, - {"ELEMADD ", "<b>%s</b>"}, -/* {"ELEMDIV ", "<hr width=100%%>"}, */ - {"ELEMDIV ", "\n"}, - {"REFERER ", "FUNC link_referer"}, - {"INDEX ", "<a href=\"index\">%s</a>\n"}, - {"SERVERROOT ", "FUNC serverroot"}, - {"RESTART ", "<a href=\"pcontrol\">%s</a>\n"}, - {"ACCESS ", "FUNC makeurl"}, - {"COMMIT ", "<a href=\"commit?commit\">%s</a>\n"}, - {"BACKOUT ", "<center>If you don't want to %s, you can <a href=index>" - "return to the server manager.</a></center>\n"}, - {"CURSERVNAME", "FUNC curservname"}, - {"VERIFY ", "FUNC verify"}, - {"HELPBUTTON", "FUNC helpbutton"}, - {"DIALOGSUBMIT", "FUNC dialogsubmit"}, - {"HELPJSFN", "FUNC helpjsfn"} -}; - -int get_directive(char *string); -void conditional(char *input, char **vars, int index); -void respicker(char **config); -void currentres(char **config); -void prevres(char **config); -void booktrack(char *input, char **vars); -void docswitcher(char *input); -void docroot(char **vars); -void link_referer(char **input, char **vars); -void serverroot(char **vars); -char **get_vars(char *string); -static void output(char *string); -void makeurl(char **vars); -void curservname(void); -void pageheader(char **vars, char **config); -void submit(int verify, char **vars); -void helpbutton(char *topic); -void dialogsubmit(char *topic); - -static int status = -1; - -/* Filter a page. Takes the page to filter as an argument. Uses above - * filters to process. - */ -NSAPI_PUBLIC int parse_line(char *line_input, char **input) -{ - register int index; - char *position; - int dirlen = strlen(DIRECTIVE_START); - char **vars; - - - if(!strncmp(line_input, DIRECTIVE_START, dirlen)) { - position = (char *) (line_input + dirlen); - index = get_directive(position); - - /* did we get one? */ - if(index != -1) { - /* if so, get the vars. */ - position += strlen(templates[index].name); - vars = get_vars(position); - /* Dispatch the correct function (done for readability, - * although I'm starting to wonder if I should bother) - */ - if(!strncmp(templates[index].format, "FUNC ", 5)) { - - if(!strncmp(templates[index].format+5, "conditional", 11)) - conditional(input[0], vars, index); - else if(!strncmp(templates[index].format+5, "respicker", 9)) - respicker(input); - else if(!strncmp(templates[index].format+5, "booktrack", 9)) - booktrack(input[0], vars); - else if(!strncmp(templates[index].format+5, "docswitcher", 11)) - docswitcher(input[0]); - else if(!strncmp(templates[index].format+5, "docroot", 7)) - docroot(vars); - else if(!strncmp(templates[index].format+5, "link_referer",12)) - link_referer(input, vars); - else if(!strncmp(templates[index].format+5, "serverroot",10)) - serverroot(vars); - else if(!strncmp(templates[index].format+5, "makeurl",7)) - makeurl(vars); - else if(!strncmp(templates[index].format+5, "curservname",11)) - curservname(); - else if(!strncmp(templates[index].format+5, "pageheader",10)) - pageheader(vars, input); - else if(!strncmp(templates[index].format+5, "submit",6)) - submit(0, vars); - else if(!strncmp(templates[index].format+5, "verify",6)) - submit(1, vars); - else if(!strncmp(templates[index].format+5, "helpbutton",10)) - helpbutton(vars[0]); - else if(!strncmp(templates[index].format+5, "dialogsubmit",12)) - dialogsubmit(vars[0]); - /* We don't know what this template is. Send it back. */ - else return -1; - } else { - /* I just can't believe there's no easy way to create - * a va_list. */ - char line[BIG_LINE]; - sprintf(line, templates[index].format, - (vars[0] != NULL) ? vars[0]: "", - (vars[1] != NULL) ? vars[1]: "", - (vars[2] != NULL) ? vars[2]: "", - (vars[3] != NULL) ? vars[3]: ""); - output(line); - } - } else { - /* We found a directive, but we can't identify it. Send it back.*/ - /* Check status first; if we're not supposed to be outputing */ - /* because of an "IF" block, don't tell the program to */ - /* try and cope with it. */ - if(status) - return -1; - else - return 0; - } - } else - /* We found no directive. The line is normal. */ - output(line_input); - - /* If we're here, we either handled it correctly or the line was benign.*/ - return 0; -} - -void conditional(char *input, char **vars, int index) -{ - if((!strncmp(templates[index].name, "IF", 2)) && - (vars[0] != NULL)) { - status = input[atoi(vars[0])] - '0'; - } else - if((!strncmp(templates[index].name, "ELSE", 4)) && - (status != -1)) { - status ^= 1; - } else - if(!strncmp(templates[index].name, "ENDIF", 5)) - status = -1; -} - -void respicker(char **config) -{ - output("<FORM action=rsrcpckr method=GET>\n"); - output("<hr size=4><center>\n"); - prevres(config); - output("</center><hr size=4>\n"); - output("</FORM>\n"); -} - -void currentres(char **config) -{ - int l; - char line[BIG_LINE]; - char *resname, *restype; - - resname = get_current_resource(config); - restype = get_current_typestr(config); - if(!strcmp(restype, NAME)) { - if(!strcmp(resname, "default")) - sprintf(line, "<font size=+1>Modifying: " - "<b>the entire server</b>.</font>"); - else - sprintf(line, "<font size=+1>Modifying: " - "<b>the object named %s</b>.</font>", resname); - } - else if(!strcmp(restype, FILE_OR_DIR)) { - l = strlen(resname) - 1; - if(resname[l] == '*') { - sprintf(line, "<font size=+1>Modifying: <b>the directory " - "%s</b></font>", - resname); - } else { - sprintf(line, "<font size=+1>Modifying: <b>%s %s</b></font>", - (strchr(resname, '*')) ? "files matching" : "the file", - resname); - } - } - else if(!strcmp(restype, TEMPLATE)) { - sprintf(line, "<font size=+1>Modifying: <b>the template %s</b></font>", - resname); - } - else if(!strcmp(restype, WILDCARD)) { -#ifdef MCC_PROXY - sprintf(line, "<font size=+1>Modifying: <b>URLs matching RE %s" -#else - sprintf(line, "<font size=+1>Modifying: <b>files matching %s" -#endif - "</b></font>", - resname); - } - output(line); -} - -void prevres(char **config) -{ -#ifndef MCC_NEWS - char *res = get_current_resource(config); - int rtype = get_current_restype(config); - - if(status) { - char **options = NULL; - register int x=0; - int found=0; - int option_cnt = total_object_count(); - - fprintf(stdout, "<SCRIPT language=JavaScript>\n"); - fprintf(stdout, "function checkForClick() {\n"); - fprintf(stdout, " document.forms[0].resource.blur();\n"); - fprintf(stdout, " var idx=document.forms[0]." - "resource.options.selectedIndex;\n"); - fprintf(stdout, " if(document.forms[0].resource." - "options[idx].defaultSelected == 0) {\n"); - fprintf(stdout, " document.forms[0].submit();\n"); - fprintf(stdout, " return 1;\n"); - fprintf(stdout, " } else return 0;\n"); - fprintf(stdout, "}\n"); - fprintf(stdout, "</SCRIPT>\n"); - -#ifdef MCC_PROXY - fprintf(stdout, "<TABLE BORDER=0>\n"); - fprintf(stdout, "<TR><TD><font size=+1>Editing:</font></TD>\n"); - fprintf(stdout, - "<TD><SELECT name=\"resource\" onChange=\"checkForClick()\" SIZE=\"%d\">\n", - option_cnt <= 20 ? 1 : 5); -#else - output("<nobr>"); - fputs("<font size=+1>Editing:</font>\n", stdout); - fprintf(stdout, "<SELECT name=\"resource\" " - "onChange=\"checkForClick()\" %s>\n", - option_cnt <=20 ? "" : "size=5"); -#endif - -#ifdef MCC_HTTPD /* template->styles nightmare */ - if((rtype==PB_NAME) && (strcmp(res, "default"))) { - /* enter: STYLES MODE */ - fprintf(stdout, "<OPTION value=ndefault>Exit styles mode\n"); - } else { - fprintf(stdout, "<OPTION value=ndefault %s>The entire server\n", - (!strcmp(res, "default")) ? "SELECTED" : ""); - } -#else - fprintf(stdout, "<OPTION value=ndefault %s>The entire server\n", - (!strcmp(res, "default")) ? "SELECTED" : ""); -#endif - if(!strcmp(res, "default")) found=1; - options = list_objects(PB_PATH); -#ifdef MCC_HTTPD /* template->styles nightmare */ - if((options) && !((rtype==PB_NAME) && (strcmp(res, "default"))) ) { -#else - if(options) { -#endif - for(x=0; options[x]; x++) { - fprintf(stdout, "<OPTION value=f%s %s>%s\n", - options[x], - (!strcmp(options[x], res)) ? "SELECTED" : "", - options[x]); - if(!strcmp(options[x], res)) found=1; - } - } - options=list_objects(PB_NAME); -#ifdef MCC_HTTPD /* template->styles nightmare */ - if((options) && ((rtype==PB_NAME) && (strcmp(res, "default"))) ) { -#else - if(options) { -#endif - for(x=0; options[x]; x++) { - if(!strcmp(options[x], "default") || - !strcmp(options[x], "cgi")) - continue; -#ifdef MCC_HTTPD /* template->style usability */ - fprintf(stdout, "<OPTION value=n%s %s>The style '%s'\n", - options[x], - (!strcmp(options[x], res)) ? "SELECTED":"", - options[x]); -#else - fprintf(stdout, "<OPTION value=n%s %s>The template '%s'\n", - options[x], - (!strcmp(options[x], res)) ? "SELECTED":"", - options[x]); -#endif - if(!strcmp(options[x], res)) found=1; - } - } - if(!found) { - if(rtype==PB_NAME) { - fprintf(stdout, "<OPTION value=n%s SELECTED>The template %s\n", - res, res); - } else { - fprintf(stdout, "<OPTION value=f%s SELECTED>%s\n", - res, res); - } - } - fputs("</SELECT></nobr>\n", stdout); - fputs("<nobr>", stdout); -#ifndef MCC_PROXY - fprintf(stdout, "<INPUT type=button value=\"Browse...\" " - "onClick=\"window.location='rsrcpckr?b'\"> "); -#endif -#ifdef MCC_PROXY - fprintf(stdout, "</TD>\n<TD>"); - fprintf(stdout, "<INPUT type=button value=\"Regular Expression...\" " - "onClick=\"var pat=" - "prompt('Enter the regular expression to edit:', ''); " -#else - fprintf(stdout, "<INPUT type=button value=\"Wildcard...\" " - "onClick=\"var pat=" - "prompt('Enter the wildcard pattern to edit:', ''); " -#endif - "if(pat!=null) window.location='rsrcpckr?" - "type="WILDCARD"&resource='+escape(pat);\">"); -#ifdef MCC_PROXY - fprintf(stdout, "</TD>\n</TR>\n</TABLE>\n"); -#endif - fputs("</nobr>", stdout); - /* output("</td></tr>\n"); */ - } -#endif -} - -void booktrack(char *input, char **vars) -{ - char line[BIG_LINE]; - - if((vars[0] != NULL) && (vars[1] != NULL)) { - sprintf(line, "<a href=index?0>" - "<img src=\"%s\" hspace=8 align=%s alt=\"\"></a>", - (input[0] - '0') ? vars[0] : vars[1], - (vars[2] != NULL) ? vars[2] : "none"); - output(line); - } -} - -void docswitcher(char *input) -{ - char line[BIG_LINE]; - char *whichimg, *whatmode; -#ifdef USE_ADMSERV - char *qs = getenv("QUERY_STRING"); - char *sname = getenv("SCRIPT_NAME"); - char *mtmp; - - char *tmp = getenv("SERVER_NAMES"); - char *servers = NULL; - if(tmp) servers = STRDUP(tmp); -#endif - - if(!(input[0] - '0')) { - whichimg = "b-clsd.gif"; - whatmode = "Express mode"; - } else { - whichimg = "b-open.gif"; - whatmode = "Full docs"; - } - - mtmp = (char *) MALLOC( (sname? strlen(sname) : 0) + - (qs? strlen(qs) : 0) + - (strlen(whichimg) + strlen(whatmode)) + - 1024); - sprintf(mtmp, "<center><table border=2 width=95%%>\n" - "<tr><td rowspan=2><a href=index%s>" - "<img src=\"../icons/%s\" " - "alt=\"[%s] \" border=2>" - "</td>\n", - (qs ? "?0" : sname), - whichimg, whatmode); - output(mtmp); - -#ifdef USE_ADMSERV - if(!servers) { - sprintf(line, "<td width=100%% align=center rowspan=2><b>%s</b></td>\n", - whatmode); - output(line); - } else - if(servers[0] == '(') { - - sprintf(line, "<td width=100%% align=center>Current servers:<br>\n"); - output(line); - output("<b>"); - - tmp=strtok(++servers, "|)"); - while(tmp) { - char *tmp2; - output("<nobr>"); - tmp2=strchr(tmp, '-'); - tmp2++; - output(tmp2); - tmp=strtok(NULL, "|)"); - if(tmp) - output(","); - output("</nobr>\n"); - } - output("</b></td>\n"); - } else { - - sprintf(line, "<td width=100%% align=center>Current server: "); - output(line); - output("<b>"); - tmp = strchr(servers, '-'); - *tmp++ = '\0'; - output(tmp); - output("</b>"); - output("</td>\n"); - } -#endif - sprintf(mtmp, "<td rowspan=2><a href=index%s>" - "<img src=\"../icons/%s\" " - "alt=\"\" border=2></a></td></tr>\n", - (qs? "?0" : sname), - whichimg); - output(mtmp); -#ifdef USE_ADMSERV - if(servers) { - sprintf(line, "<tr><td align=center>" - "<a href=\"/admin-serv/bin/chooser\">" - "Choose</a> a new server or set of servers</a></td>\n"); - output(line); - } -#endif - sprintf(line, "</tr></table></center>\n"); - output(line); - output("<hr width=10%%>\n"); -} - -void docroot(char **vars) -{ -#ifndef MCC_NEWS - char line[BIG_LINE]; - pblock *pb = grab_pblock(PB_NAME, "default", "NameTrans", "document-root", - NULL, NULL); - char *docroot = ""; - if(pb) - docroot = pblock_findval("root", pb); - sprintf(line, "<b>%s%s</b>\n", docroot, (vars[0] != NULL) ? vars[0] : ""); - output(line); -#endif -} - -void serverroot(char **vars) -{ - char line[BIG_LINE]; -#ifdef USE_ADMSERV - char *sroot = getenv("NETSITE_ROOT"); -#else - char *sroot = get_mag_var("#ServerRoot"); -#endif - sprintf(line, "%s%s", (sroot) ? sroot : "", (vars[0]) ? vars[0] : ""); - output(line); -} - -void makeurl(char **vars) -{ - char line[BIG_LINE]; - - sprintf(line,"<a href=%s target=_blank>%s</a>\n", - get_serv_url(), vars[0] ? vars[0] : ""); - output(line); -} - -void curservname(void) -{ - output(get_srvname(0)); -} - -NSAPI_PUBLIC -void pageheader(char **vars, char **config) -{ - char line[BIG_LINE]; -#if 0 /* MLM - put in to have non-working Back button */ - char *ref=get_referer(config); - char *t; -#endif - - output("<center><table border=2 width=100%%>\n"); - - util_snprintf(line, BIG_LINE, "<tr>"); - output(line); - - util_snprintf(line, BIG_LINE, "<td align=center width=100%%>"); - output(line); - util_snprintf(line, BIG_LINE, "<hr size=0 width=0>"); - output(line); -#if 0 /* MLM - put in to have non-working Back button */ - t=strrchr(ref, '/'); - *t++='\0'; - util_snprintf(line, BIG_LINE, "<a href=\"%s/index/%s\">", ref, t); - output(line); - util_snprintf(line, BIG_LINE, "<img align=right src=../icons/back.gif " - "width=41 height=26 border=0></a>\n"); - output(line); -#endif - util_snprintf(line, BIG_LINE, "<FONT size=+2><b>%s</b></FONT>" - "<hr size=0 width=0>" - "</td>", vars[2]); - output(line); - - output("</tr></table></center>\n"); -} - -char *_get_help_button(char *topic) -{ - char line[BIG_LINE]; - - util_snprintf( line, BIG_LINE, - "<input type=button value=\"%s\" " - "onClick=\"%s\">", XP_GetAdminStr(DBT_help_), - topic ? helpJavaScriptForTopic( topic ) : helpJavaScript() ); - - return(STRDUP(line)); -} NSAPI_PUBLIC char *helpJavaScriptForTopic( char *topic ) { char *tmp; char line[BIG_LINE]; - char *server=get_srvname(0); + char *server="admserv"; char *type; int typeLen; @@ -605,216 +58,3 @@ NSAPI_PUBLIC char *helpJavaScript() *sn++='\0'; return helpJavaScriptForTopic( sn ); } - -void submit(int verify, char **vars) -{ - char line[BIG_LINE]; - char outline[BIG_LINE]; - - if(verify) { - util_snprintf(line, BIG_LINE, "<SCRIPT language="MOCHA_NAME">\n" - "function verify(form) {\n" - " if(confirm('Do you really want to %s?'))\n" - " form.submit();\n" - "}\n" - "</SCRIPT>\n", vars[0]); - output(line); - } - - output("<center><table border=2 width=100%%><tr>"); - - if(!verify) { - util_snprintf(outline, BIG_LINE, "%s%s%s%s%s", - "<td width=33%% align=center>", - "<input type=submit value=\"", - XP_GetAdminStr(DBT_ok_), - "\">", - "</td>\n"); - } else { - util_snprintf(outline, BIG_LINE, "%s%s%s%s%s%s", - "<td width=33%% align=center>", - "<input type=button value=\"", - XP_GetAdminStr(DBT_ok_), - "\" ", - "onclick=\"verify(this.form)\">", - "</td>\n"); - } - output(outline); - util_snprintf(outline, BIG_LINE, "%s%s%s%s", - "<td width=34%% align=center>", - "<input type=reset value=\"", - XP_GetAdminStr(DBT_reset_), - "\"></td>\n"); - output(outline); - - util_snprintf(line, BIG_LINE, "<td width=33%% align=center>%s</td>\n", - _get_help_button( vars[0] )); - output(line); - - output("</tr></table></center>\n"); - - output("</form>\n"); - - output("<SCRIPT language="MOCHA_NAME">\n"); - output("</SCRIPT>\n"); -} - -void helpbutton(char *topic) -{ - output("<form><p><div align=right><table width=33%% border=2>" - "<tr><td align=center>"); - output(_get_help_button(topic)); - output("</td></tr></table></div></form>\n"); - output("<SCRIPT language="MOCHA_NAME">\n"); - output("</SCRIPT>\n"); -} - -void dialogsubmit(char *topic) -{ - char line[BIG_LINE]; - char outline[BIG_LINE]; - - output("<center><table border=2 width=100%%><tr>"); - - util_snprintf(outline, BIG_LINE, "%s%s%s%s%s", - "<td width=33%% align=center>", - "<input type=submit value=\"", - XP_GetAdminStr(DBT_done_), - "\">", - "</td>\n"); - output(outline); - util_snprintf(outline, BIG_LINE, "%s%s%s%s%s", - "<td width=34%% align=center>", - "<input type=button value=\"", - XP_GetAdminStr(DBT_cancel_), - "\" " - "onClick=\"top.close()\"></td>\n"); - output(outline); - - util_snprintf(line, BIG_LINE, "<td width=33%% align=center>%s</td>\n", - _get_help_button(topic)); - output(line); - - output("</tr></table></center>\n"); - - output("</form>\n"); - - output("<SCRIPT language="MOCHA_NAME">\n"); - output("</SCRIPT>\n"); -} - -void helpjsfn(void) -{ - char *tmp; - char line[BIG_LINE]; - char *server=get_srvname(0); - char *type; - int typeLen; - - /* Get the server type, without the instance name into type */ - tmp = strchr( server, '-' ); - typeLen = tmp - server; - - type = (char *)MALLOC( typeLen + 1 ); - type[typeLen] = '\0'; - while ( typeLen-- ) { - type[typeLen] = server[typeLen]; - } - - output("function displayHelpTopic(topic)\n"); - output("{\n"); - util_snprintf(line, BIG_LINE, - " if (top.helpwin) {\n" - " top.helpwin.focus();\n" - " top.helpwin.infotopic.location='%s/%s/admin/tutor?!' + topic;\n" - " } else {\n" - " window.open('%s/%s/admin/tutor?' + topic, '" - INFO_IDX_NAME"_%s', " - HELP_WIN_OPTIONS");\n" - " }\n" - "}\n", - getenv("SERVER_URL"), server, - getenv("SERVER_URL"), server, - type ); - output(line); -} - -void link_referer(char **input, char **vars) -{ - char line[BIG_LINE]; - - sprintf( line, "<SCRIPT language="MOCHA_NAME">\n" - "document.writeln( '%s'.link( '%s' ) );\n" - "</SCRIPT>\n", ( vars[0] ? vars[0] : getenv( "SCRIPT_NAME" ) ), - cookieValue( "adminReferer", NULL ) ); - output( line ); -} - -int get_directive(char *string) -{ - int index = -1; - register int x; - - for(x=0; x < MAXTEMPLATE; x++) { - if(!strncmp(string, templates[x].name, - strlen(templates[x].name))) { - index = x; - break; - } - } - return index; -} - -NSAPI_PUBLIC int directive_is(char *target, char *directive) -{ - char *position = (target + strlen(DIRECTIVE_START)); - return(!(strncmp(directive, position, strlen(directive)))); -} - -char **get_vars(char *string) -{ - char **vars; - register int x; - int isvar; - char scratch[BIG_LINE]; - char lastchar; - -/* Initialize the vars array. - */ - vars = (char **) MALLOC((MAXVARS)*(sizeof(char *))); - for(x=0; x< MAXVARS; x++) - vars[x] = NULL; - - isvar = -1; - x = 0; - scratch[0] = '\0'; - lastchar = ' '; - - while(*string != '\0') { - if((*string == '\"') && (lastchar != '\\')) - if(isvar != -1) { - vars[x++] = (char *)STRDUP(scratch); - isvar = -1; - if(x == MAXVARS) - break; - } else - isvar = 0; - else - if(isvar != -1) { - scratch[isvar++] = *string; - scratch[isvar] = '\0'; - } - else - if(*string == DIRECTIVE_END) - break; - lastchar = *string; - string++; - } - return vars; -} - -static void output(char *line) -{ - if(status) - fputs(line, stdout); -} diff --git a/lib/libadmin/util.c b/lib/libadmin/util.c index b560055d..4af302f0 100644 --- a/lib/libadmin/util.c +++ b/lib/libadmin/util.c @@ -13,12 +13,12 @@ #include "base/util.h" #include "private/pprio.h" +#include <base/file.h> #ifdef XP_UNIX #include <dirent.h> #include <sys/types.h> #include <fcntl.h> #else -#include <base/file.h> #include <sys/stat.h> #endif /* WIN32? */ @@ -26,675 +26,6 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <ctype.h> /* isdigit */ - -#define NUM_ENTRIES 64 - -#ifdef MCC_PROXY -char * -XP_GetString() -{ - return "ZAP"; -} -#endif - -#ifdef XP_WIN32 -char *GetQueryNT(void) -{ - char *qs = getenv("QUERY_STRING"); - if(qs && (*qs == '\0')) - qs = NULL; - return qs; -} -#endif /* XP_WIN32 */ - -void escape_for_shell(char *cmd) { - register int x,y,l; - - l=strlen(cmd); - for(x=0;cmd[x];x++) { - if(strchr(" &;`'\"|*!?~<>^()[]{}$\\\x0A",cmd[x])){ - for(y=l+1;y>x;y--) - cmd[y] = cmd[y-1]; - l++; /* length has been increased */ - cmd[x] = '\\'; - x++; /* skip the character */ - } - } -} - -int _admin_dumbsort(const void *s1, const void *s2) -{ - return strcmp(*((char **)s1), *((char **)s2)); -} - -#ifdef XP_UNIX /* WIN32 change */ -/* Lists all files in a directory. */ -char **list_directory(char *path, int dashA) -{ - char **ar; - DIR *ds; - struct dirent *d; - int n, p; - - n = NUM_ENTRIES; - p = 0; - - ar = (char **) MALLOC(n * sizeof(char *)); - - if(!(ds = opendir(path))) { - return NULL; - } - - while( (d = readdir(ds)) ) { - if ( ( d->d_name[0] != '.' ) || - ( dashA && d->d_name[1] && - ( d->d_name[1] != '.' || d->d_name[2] ) ) ) { - if(p == (n-1)) { - n += NUM_ENTRIES; - ar = (char **) REALLOC(ar, n*sizeof(char *)); - } - /* 2: Leave space to add a trailing slash later */ - ar[p] = (char *) MALLOC(strlen(d->d_name) + 2); - strcpy(ar[p++], d->d_name); - } - } - closedir(ds); - - qsort((void *)ar, p, sizeof(char *), _admin_dumbsort); - ar[p] = NULL; - - return ar; -} - -#else /* WIN32 change */ -/* Lists all files in a directory. */ -char **list_directory(char *path, int dashA) -{ - char **ar; - SYS_DIR ds; - SYS_DIRENT *d; - int n, p; - - n = NUM_ENTRIES; - p = 0; - - ar = (char **) MALLOC(n * sizeof(char *)); - - if(!(ds = dir_open(path))) { - return NULL; - } - - while( (d = dir_read(ds)) ) { - if ( ( d->d_name[0] != '.' ) || - ( dashA && d->d_name[1] && - ( d->d_name[1] != '.' || d->d_name[2] ) ) ) { - if(p == (n-1)) { - n += NUM_ENTRIES; - ar = (char **) REALLOC(ar, n*sizeof(char *)); - } - /* 2: Leave space to add a trailing slash later */ - ar[p] = (char *) MALLOC(strlen(d->d_name) + 2); - strcpy(ar[p++], d->d_name); - } - } - dir_close(ds); - - qsort((void *)ar, p, sizeof(char *), _admin_dumbsort); - ar[p] = NULL; - - return ar; -} -#endif /* WIN32 */ - -int file_exists(char *fn) -{ - struct stat finfo; - - if(!stat(fn, &finfo)) - return 1; - else - return 0; -} - -int get_file_size(char *fn) -{ - struct stat finfo; - int ans = -1; - - if(!stat(fn, &finfo)) { - ans = finfo.st_size; - } else { - report_error(FILE_ERROR, fn, "Could not get size of file."); - } - return ans; -} - -int ADM_mkdir_p(char *dir, int mode) -{ - char path[PATH_MAX]; - struct stat fi; - char *slash = NULL; - - if (dir) - strcpy (path, dir); - else - return 0; - - if (slash = strchr(path, FILE_PATHSEP)) - slash++; /* go past root */ - else - return 0; - - while (slash && *slash) { - slash = strchr(slash, FILE_PATHSEP); - if (slash) *slash = '\0'; /* check path till here */ - - if (stat(path, &fi) == -1) { -#ifdef XP_UNIX - if (mkdir(path, mode) == -1) -#else /* XP_WIN32 */ - if (!CreateDirectory(path, NULL)) -#endif - return 0; - } - - if (slash) { - *slash = FILE_PATHSEP; /* restore path */ - slash++; /* check remaining path */ - } - } - return 1; -} - -int ADM_copy_directory(char *src_dir, char *dest_dir) -{ - SYS_DIR ds; - SYS_DIRENT *d; - struct stat fi; - char src_file[PATH_MAX], dest_file[PATH_MAX], fullname[PATH_MAX]; - - if (!(ds = dir_open(src_dir))) - report_error(FILE_ERROR, "Can't read directory", src_dir); - - while (d = dir_read(ds)) { - if (d->d_name[0] != '.') { - sprintf(fullname, "%s/%s", src_dir, d->d_name); - if (system_stat(fullname, &fi) == -1) - continue; - - sprintf(src_file, "%s%c%s", src_dir, FILE_PATHSEP, d->d_name); - sprintf(dest_file, "%s%c%s", dest_dir, FILE_PATHSEP, d->d_name); - if (S_ISDIR(fi.st_mode)) { - char *sub_src_dir = STRDUP(src_file); - char *sub_dest_dir = STRDUP(dest_file); - if (!ADM_mkdir_p(sub_dest_dir, 0755)) { - report_error(FILE_ERROR, "Cannot create directory", - sub_dest_dir); - return 0; - } - if (!ADM_copy_directory(sub_src_dir, sub_dest_dir)) - return 0; - FREE(sub_src_dir); - FREE(sub_dest_dir); - } - else - cp_file(src_file, dest_file, 0644); - } - } - dir_close(ds); - return(1); -} - -void ADM_remove_directory(char *path) -{ - struct stat finfo; - char **dirlisting; - register int x=0; - int stat_good = 0; - char *fullpath = NULL; - -#ifdef XP_UNIX - stat_good = (lstat(path, &finfo) == -1 ? 0 : 1); -#else /* XP_WIN32 */ - stat_good = (stat(path, &finfo) == -1 ? 0 : 1); -#endif - - if(!stat_good) return; - - if(S_ISDIR(finfo.st_mode)) { - dirlisting = list_directory(path,1); - if(!dirlisting) return; - - for(x=0; dirlisting[x]; x++) { - fullpath = (char *) MALLOC(strlen(path) + - strlen(dirlisting[x]) + 4); - sprintf(fullpath, "%s%c%s", path, FILE_PATHSEP, dirlisting[x]); -#ifdef XP_UNIX - stat_good = (lstat(fullpath, &finfo) == -1 ? 0 : 1); -#else /* XP_WIN32 */ - stat_good = (stat(fullpath, &finfo) == -1 ? 0 : 1); -#endif - if(!stat_good) continue; - if(S_ISDIR(finfo.st_mode)) { - ADM_remove_directory(fullpath); - } else { - unlink(fullpath); - } - FREE(fullpath); - } -#ifdef XP_UNIX - rmdir(path); -#else /* XP_WIN32 */ - RemoveDirectory(path); -#endif - } else { - delete_file(path); - } - return; -} - -/* return: mtime(f1) < mtime(f2) ? */ -int mtime_is_earlier(char *file1, char *file2) -{ - struct stat fi1, fi2; - - if(stat(file1, &fi1)) { - return -1; - } - if(stat(file2, &fi2)) { - return -1; - } - return( (fi1.st_mtime < fi2.st_mtime) ? 1 : 0); -} - -time_t get_mtime(char *fn) -{ - struct stat fi; - - if(stat(fn, &fi)) - return 0; - return fi.st_mtime; -} - -int all_numbers(char *target) -{ - register int x=0; - - while(target[x]) - if(!isdigit(target[x++])) - return 0; - return 1; -} - - -int all_numbers_float(char *target) -{ - register int x; - int seenpt; - - for(x = 0, seenpt = 0; target[x]; ++x) { - if((target[x] == '.') && (!seenpt)) - seenpt = 1; - else if((!isdigit(target[x])) && seenpt) - return 0; - } - return 1; -} - -/* Get the admin/config directory. */ -char *get_admcf_dir(int whichone) -{ -#ifdef USE_ADMSERV - char *confdir = NULL; - - char *tmp = get_num_mag_var(whichone, "#ServerRoot"); - if(!tmp) { - /* sigh */ - report_error(INCORRECT_USAGE, "No server root variable", - "The magnus.conf variable #ServerRoot was " - "not set. Please set the value of your server " - "root through the administrative forms."); - } - confdir = (char *) MALLOC(strlen(tmp) + strlen("config") + 4); - sprintf(confdir, "%s%cconfig%c", tmp, FILE_PATHSEP, FILE_PATHSEP); - - return confdir; -#else - char *confdir; - char line[BIG_LINE]; - sprintf(line, "%s%cadmin%cconfig%c", get_mag_var("#ServerRoot"), - FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP); - confdir = STRDUP(line); -#endif - return STRDUP(confdir); -} - -/* Get the current HTTP server URL. */ -char *get_serv_url(void) -{ -#ifdef USE_ADMSERV - char *name = get_mag_var("ServerName"); - char *port = get_mag_var("Port"); - char *protocol = NULL; - char line[BIG_LINE]; - -#ifndef NS_UNSECURE - char *security = get_mag_var("Security"); - - if(!security || strcasecmp(security, "on")) { - protocol = STRDUP("http"); - if(!strcmp(port, "80")) - port = STRDUP(""); - else { - sprintf(line, ":%s", port); - port = STRDUP(line); - } - } else { - protocol = STRDUP("https"); - if(!strcmp(port, "443")) - port = STRDUP(""); - else { - sprintf(line, ":%s", port); - port = STRDUP(line); - } - } -#else - protocol = STRDUP("http"); - if(!strcmp(port, "80")) - port = STRDUP(""); - else { - sprintf(line, ":%s", port); - port = STRDUP(line); - } -#endif - - sprintf(line, "%s://%s%s", protocol, name, port); - return(STRDUP(line)); -#else - return(getenv("SERVER_URL")); -#endif -} - -/* ------------------------------- run_cmd -------------------------------- */ - - -/* Previously in install. This is also pretty UNIX-ish. */ - -/* Nirmal: Added code for Win32 implementation of this function. */ - -#include <signal.h> -#ifdef XP_UNIX -#include <sys/wait.h> -#endif /* XP_UNIX */ - - -int run_cmd(char *cmd, FILE *closeme, struct runcmd_s *rm) -{ -#ifdef WIN32 - HANDLE hproc; - PROCESS_INFORMATION child; - STARTUPINFO siStartInfo ; -#else - struct stat fi; - int exstat; - char *errmsg, tfn[128]; - FILE *f; - int fd; - pid_t pid; -#endif - - -#ifdef WIN32 - /* Nirmal: - For now, i will just spawn - a child in WINNT to execute the command. Communication to - the parent is done through stdout pipe, that was setup by - the parent. - - */ - hproc = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, GetCurrentProcessId()); - if (hproc == NULL) { - fprintf(stdout, "Content-type: text/html\n\n"); - fflush(stdout); - report_error(SYSTEM_ERROR, NULL, "Could not open handle to myself"); - return -1; // stmt. not reached. - } - - ZeroMemory(&child, sizeof(PROCESS_INFORMATION)); - ZeroMemory(&siStartInfo, sizeof(STARTUPINFO)); - siStartInfo.cb = sizeof(STARTUPINFO); - siStartInfo.lpReserved = siStartInfo.lpReserved2 = NULL; - siStartInfo.cbReserved2 = 0; - siStartInfo.lpDesktop = NULL; - siStartInfo.dwFlags = STARTF_USESHOWWINDOW; -// Several fields arent used when dwFlags is not set. -// siStartInfo.hStdInput = hChildStdinRd; -// siStartInfo.hStdOutput = siStartInfo.hStdError = hChildStdoutWr; - siStartInfo.wShowWindow = SW_HIDE; - - if ( ! CreateProcess( - NULL, // pointer to name of executable module - cmd, // pointer to command line string - NULL, // pointer to process security attribute - NULL, // pointer to thread security attributes - TRUE, // handle inheritance flag - 0, // creation flags - NULL, // pointer to new environment block - NULL, // pointer to current directory name - &siStartInfo, // pointer to STARTUPINFO - &child // pointer to PROCESS_INFORMATION - )) - { - rm->title = "CreateProcess failed"; - rm->msg = "run_cmd: Can't create new process. "; - rm->arg = ""; - rm->sysmsg = 1; - return -1; - } - else - return 0; -#else - sprintf(cmd, "%s > /tmp/startmsg.%d 2>&1 < /dev/null", cmd, getpid()); /* */ - /* FUCK UNIX SIGNALS. */ - signal(SIGCHLD, SIG_DFL); - switch( (pid = fork()) ) { - case 0: - /* Hmm. Work around an apparent bug in stdio. */ - if(closeme) - close(fileno(closeme)); - execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL); - /* DOH! */ - sprintf(tfn, "/tmp/startmsg.%d", getpid()); - if(!(f = fopen(tfn, "w"))) - exit(1); - fprintf(f, "Exec of %s failed. The error was %s.\n", cmd, - system_errmsg()); - fclose(f); - exit(1); - case -1: - rm->title = "Fork failed"; - rm->msg = "Can't create new process. %s"; - rm->arg = ""; - rm->sysmsg = 1; - return -1; - default: - sprintf(tfn, "/tmp/startmsg.%d", getpid()); - - if(waitpid(pid, &exstat, 0) == -1) { - rm->title = "Can't wait for child"; - rm->msg = "Can't wait for process. %s"; - rm->arg = ""; - rm->sysmsg = 1; - return -1; - } - if(exstat) { - if(!(fd = open(tfn, O_RDONLY))) { - rm->title = "Can't open error file"; - rm->msg = "Can't find error file %s."; - rm->arg = cmd; - rm->sysmsg = 1; - return -1; - } - fstat(fd, &fi); - if((fi.st_size > 0) && (fi.st_size < 8192)) { - errmsg = (char *) MALLOC(fi.st_size + 1); - read(fd, errmsg, fi.st_size); - errmsg[fi.st_size] = '\0'; - close(fd); - unlink(tfn); - rm->title = "Command execution failed"; - rm->msg = "The command did not execute. " - "Here is the output:<p>\n<pre>\n%s\n</pre>\n"; - rm->arg = errmsg; - rm->sysmsg = 0; - return -1; - } - else { - close(fd); - unlink(tfn); - - rm->title = "Command execution failed"; - rm->msg = "The command didn't execute, and it did not produce " - "any output. Run <code>%s</code> from the command " - "line and examine the output.\n"; - rm->arg = cmd; - rm->sysmsg = 0; - return -1; - } - } - unlink(tfn); - return 0; - } -#endif /* WIN32 */ - -} - - - -/* This is basically copy_file from the install section, with the error - * reporting changed to match the admin stuff. Since some stuff depends - * on copy_file being the install version, I'll cheat and call this one - * cp_file. */ -#ifdef XP_UNIX - -#define COPY_BUFFER_SIZE 4096 - -void cp_file(char *sfile, char *dfile, int mode) -{ - int sfd, dfd, len; - struct stat fi; - - char copy_buffer[COPY_BUFFER_SIZE]; - unsigned long read_len; - -/* Make sure we're in the right umask */ - umask(022); - - if( (sfd = open(sfile, O_RDONLY)) == -1) - report_error(FILE_ERROR, sfile, "Can't open file for reading."); - - fstat(sfd, &fi); - if(!(S_ISREG(fi.st_mode))) { - close(sfd); - return; - } - len = fi.st_size; - - if( (dfd = open(dfile, O_RDWR | O_CREAT | O_TRUNC, mode)) == -1) - report_error(FILE_ERROR, dfile, "Can't write to file."); - - while(len) { - read_len = len>COPY_BUFFER_SIZE?COPY_BUFFER_SIZE:len; - - if ( (read_len = read(sfd, copy_buffer, read_len)) == -1) { - report_error(FILE_ERROR, sfile, "Error reading file for copy."); - } - - if ( write(dfd, copy_buffer, read_len) != read_len) { - report_error(FILE_ERROR, dfile, "Error writing file for copy."); - } - - len -= read_len; - } - close(sfd); - close(dfd); -} - -#else /* XP_WIN32 */ -void cp_file(char *sfile, char *dfile, int mode) -{ - HANDLE sfd, dfd, MapHandle; - PCHAR fp; - DWORD BytesWritten = 0; - DWORD len; - - if( (sfd = CreateFile(sfile, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) - == INVALID_HANDLE_VALUE) { - report_error(FILE_ERROR, "Cannot open file for reading", sfile); - } - len = GetFileSize(sfd, NULL); - if( (dfd = CreateFile(dfile, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { - report_error(FILE_ERROR, "Cannot open destination file for writing", - dfile); - } - if (len == 0) - return; - if( (MapHandle = CreateFileMapping(sfd, NULL, PAGE_READONLY, - 0, 0, NULL)) == NULL) { - report_error(FILE_ERROR, "Cannot create file mapping", sfile); - } - if (!(fp = MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0))) { - report_error(FILE_ERROR, "Cannot map file %s", sfile); - } - while ( len) { - if(!WriteFile(dfd, fp, len, &BytesWritten, NULL)) { - report_error(FILE_ERROR, "Cannot write new file", dfile); - } - len -= BytesWritten; - fp += BytesWritten; - } - - CloseHandle(sfd); - UnmapViewOfFile(fp); - CloseHandle(MapHandle); - FlushFileBuffers(dfd); - CloseHandle(dfd); -} -#endif - -int delete_file(char *path) -{ -#ifdef XP_UNIX - return unlink(path); -#else - return !(DeleteFile(path)); -#endif -} - -void create_dir(char *dir, int mode) -{ - if ((dir == (char *) NULL) || (strlen(dir) == 0)) { - report_error(FILE_ERROR, "No directory is specified", - "Could not create a necessary directory."); - } - - if(!file_exists(dir)) { -#ifdef XP_UNIX - if(mkdir(dir, mode) == -1) { -#else /* XP_WIN32 */ - if(!CreateDirectory(dir, NULL)) { - if (GetLastError() != ERROR_ALREADY_EXISTS) -#endif /* XP_WIN32 */ - report_error(FILE_ERROR, dir, - "Could not create a necessary directory."); - } - } -} #ifdef XP_UNIX SYS_FILE lf; @@ -718,7 +49,7 @@ FILE *fopen_l(char *path, char *mode) { FILE *f = fopen(path, mode); char *lockpath; - char *sn=get_srvname(0); + char *sn="admserv"; char *flp=FILE_LOCK_PATH; if(f == NULL) return NULL; @@ -760,67 +91,6 @@ void fclose_l(FILE *f) } #endif /* XP_UNIX */ } - -/* Ripped off from the client. (Sorry, Lou.) */ -/* */ -/* The magic set of 64 chars in the uuencoded data */ -unsigned char uuset[] = { -'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', -'U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n', -'o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7', -'8','9','+','/' }; - -int do_uuencode(unsigned char *src, unsigned char *dst, int srclen) -{ - int i, r; - unsigned char *p; - -/* To uuencode, we snip 8 bits from 3 bytes and store them as -6 bits in 4 bytes. 6*4 == 8*3 (get it?) and 6 bits per byte -yields nice clean bytes - -It goes like this: - AAAAAAAA BBBBBBBB CCCCCCCC -turns into the standard set of uuencode ascii chars indexed by numbers: - 00AAAAAA 00AABBBB 00BBBBCC 00CCCCCC - -Snip-n-shift, snip-n-shift, etc.... - -*/ - - for (p=dst,i=0; i < srclen; i += 3) { - /* Do 3 bytes of src */ - register char b0, b1, b2; - - b0 = src[0]; - if (i==srclen-1) - b1 = b2 = '\0'; - else if (i==srclen-2) { - b1 = src[1]; - b2 = '\0'; - } - else { - b1 = src[1]; - b2 = src[2]; - } - - *p++ = uuset[b0>>2]; - *p++ = uuset[(((b0 & 0x03) << 4) | ((b1 & 0xf0) >> 4))]; - *p++ = uuset[(((b1 & 0x0f) << 2) | ((b2 & 0xc0) >> 6))]; - *p++ = uuset[b2 & 0x3f]; - src += 3; - } - *p = 0; /* terminate the string */ - r = (unsigned char *)p - (unsigned char *)dst;/* remember how many we did */ - - /* Always do 4-for-3, but if not round threesome, have to go - clean up the last extra bytes */ - - for( ; i != srclen; i--) - *--p = '='; - - return r; -} char *alert_word_wrap(char *str, int width, char *linefeed) { @@ -881,216 +151,6 @@ char *alert_word_wrap(char *str, int width, char *linefeed) return ans; } -void remove_directory(char *path) -{ - struct stat finfo; - char **dirlisting; - register int x=0; - int stat_good = 0; - char *fullpath = NULL; - -#ifdef XP_UNIX - stat_good = (lstat(path, &finfo) == -1 ? 0 : 1); -#else /* WIN32 */ - stat_good = (stat(path, &finfo) == -1 ? 0 : 1); -#endif /* XP_UNIX */ - - if(!stat_good) return; - - if(S_ISDIR(finfo.st_mode)) { - dirlisting = list_directory(path,1); - if(!dirlisting) return; - - for(x=0; dirlisting[x]; x++) { - fullpath = (char *) MALLOC(strlen(path) + - strlen(dirlisting[x]) + 4); - sprintf(fullpath, "%s%c%s", path, FILE_PATHSEP, dirlisting[x]); -#ifdef XP_UNIX - stat_good = (lstat(fullpath, &finfo) == -1 ? 0 : 1); -#else /* WIN32 */ - stat_good = (stat(fullpath, &finfo) == -1 ? 0 : 1); -#endif /* XP_UNIX */ - if(!stat_good) continue; - if(S_ISDIR(finfo.st_mode)) { - remove_directory(fullpath); - } else { - fprintf(stdout, "<i>Removing file</i> " - "<code>%s</code><br>\n", fullpath); - unlink(fullpath); - } - FREE(fullpath); - } - fprintf(stdout, "<i>Removing directory</i> " - "<code>%s</code><br>\n", path); -#ifdef XP_UNIX - rmdir(path); -#else /* XP_WIN32 */ - RemoveDirectory(path); -#endif /* XP_WIN32 */ - } else { - fprintf(stdout, "<i>Removing file</i> <code>%s</code><br>\n", path); - unlink(path); - } - return; -} - -int str_flag_to_int(char *str_flag) -{ - if (!str_flag) - return -1; - if (!strcmp(str_flag, "1")) - return 1; - return 0; -} - -/* - * get_ip_and_mask - function to take something that may be an IP Address - * and netmaks, and validate it. It takes two possible - * - * Parmaters: char *candidate - * - * Returns NULL if it isn't a valid IP address and mask. It returns - * the IP address and mask in the form "iii.iii.iii.iii mmm.mmm.mmm.mmm" - * if it is valid. This is in a string dynamicly allocated in this - * function. - * - * Processing: the candidate is assumed to be in one of - * these two formats: - * - * 1. "iii.iii.iii.iii" (returns: "iii.iii.iii.iii 255.255.255.255") - * 2. "iii.iii.iii.iii mmm.mmm.mmm.mmm" - * 3. "iii.*", "iii.iii.*", or "iii.iii.iii.*" - * - * The rules are: - * I. If it has a space in it, it is assumed to be the delimiter in - * format 2. - * II. If it has a "*" in it, it's assumed to be format 3. - * III. If it's in format 3, the net mask returned is: - * 255.0.0.0, 255.255.0.0, or 255.255.255.0 respectivly, - * and parts of the address right of the * is replaced with 0s. - * IV. We use inet_addr on the pieces to validate them. - * - * - */ - -char *get_ip_and_mask(char *candidate) -{ - char work[BIG_LINE]; - - char *p; - char *result = NULL; - int len; - int dots = 0; - int i; - - if (candidate && strlen(candidate) < (unsigned) BIG_LINE) { - - if ((p = strchr(candidate, ' '))) { - len = p-candidate+1; - memcpy(work, candidate, len); - work[len] = '\0'; - if (inet_addr(work) != -1) { - len = strlen(candidate)-strlen(p)-1; - if (len > 0) { - memcpy(work, p+1, len); - work[len] = '\0'; - if (inet_addr(work) != -1) { - result = strdup(candidate); - } - } - } - } - else if ((p = strchr(candidate, '*')) && - (p-candidate > 1 ) && - (*(p-1) == '.') ) { - memset(work, 0, BIG_LINE); - for (i=0; candidate[i]!='*'; ++i) { - if (candidate[i+1] != '*') - work[i] = candidate[i]; - if (candidate[i] == '.') - ++dots; - } - if (dots == 1 || dots == 2 || dots == 3) { - for (i=0; i<4-dots; ++i) { - strcat(work, ".0"); - } - if (inet_addr(work) != -1) { - strcat(work, " "); - p = &work[strlen(work)]; - for (i=0; i<dots; ++i) { - if (i==0) - strcat(work, "255"); - else - strcat(work, ".255"); - } - for (i=0; i<4-dots; ++i) { - strcat(work, ".0"); - } - if (inet_addr(p) != -1) { - result = strdup(work); - } - } - } - } - else { - if (inet_addr(candidate) != -1) { - strcpy(work, candidate); - strcat(work, " 255.255.255.255"); - result = strdup(work); - } - } - } - else - result = NULL; - - return result; -} - -/* do fgets with a filebuffer *, instead of a File *. Can't use util_getline - because it complains if the line is too long. - It does throw away <CR>s, though. - */ -NSAPI_PUBLIC char *system_gets( char *line, int size, filebuffer *fb ) -{ - int c; - int i = 0; - - while ( --size ) { - switch ( c = filebuf_getc( fb ) ) { - case IO_EOF: - line[i] = '\0'; - return i ? line : NULL; - case LF: - line[i] = c; - line[i+1] = '\0'; - return line; /* got a line, and it fit! */ - case IO_ERROR: - return NULL; - case CR: - ++size; - break; - default: - line[i++] = c; - break; - } - } - /* if we got here, then we overran the buffer size */ - line[i] = '\0'; - return line; -} - -#ifndef WIN32 - -/* make a zero length file, no matter how long it was before */ -NSAPI_PUBLIC int -system_zero( SYS_FILE f ) -{ - ftruncate( PR_FileDesc2NativeHandle( f ), 0 ); - return 0; -} - -#endif - /*********************************************************************** ** FUNCTION: cookieValue ** DESCRIPTION: @@ -1163,88 +223,6 @@ cookieValue( char *var, char *val ) return NULL; } -/*********************************************************************** -** FUNCTION: jsEscape -** DESCRIPTION: -** Escape the usual suspects, so the parser javascript parser won't eat them -** INPUTS: src - the string -** OUTPUTS: NONE -** RETURN: A malloced string, containing the escaped src -** SIDE EFFECTS: -** None, except for more memory being eaten -** RESTRICTIONS: -** None -** MEMORY: One Malloc, you should free this if you care -***********************************************************************/ - -NSAPI_PUBLIC char * -jsEscape( char *src ) -{ - int needsEscaping = 0; - int i; - char *dest; - - for ( i = 0 ; src[i] ; ++i ) { - if ( src[i] == '\\' || src[i] == '\'' || src[i] == '"' ) { - ++needsEscaping; - } - } - dest = (char *)MALLOC( i + needsEscaping + 1 ); - for ( i = 0 ; *src ; ++src ) { - if ( ( *src == '\\' ) || ( *src == '\'' ) || ( *src == '"' ) ) { - dest[i++] = '\\'; /* escape */ - } - dest[i++] = *src; - } - dest[i] = '\0'; - return dest; -} - -/*********************************************************************** -** FUNCTION: jsPWDialogSrc -** DESCRIPTION: -** Put the source to the passwordDialog JavaScript function out. -** INPUTS: inScript - if true, don't put <SCRIPT> stuff out -** otherJS - if nonNULL, other javascript to execute -** OUTPUTS: None -** RETURN: None -** SIDE EFFECTS: -** clogs up stdout -** RESTRICTIONS: -** Don't use this outside of a CGI, or before the Content-type: -** MEMORY: No memory change -** ALGORITHM: -** @+@What's really going on? -***********************************************************************/ - -NSAPI_PUBLIC void -jsPWDialogSrc( int inScript, char *otherJS ) -{ - static int srcSpewed = 0; - - otherJS = otherJS ? otherJS : ""; - - if ( ! inScript ) { - fprintf( stdout, "<SCRIPT LANGUAGE=\""MOCHA_NAME"\">\n" ); - } - if ( ! srcSpewed ) { - srcSpewed = 1; - fprintf( stdout, "function passwordDialog( prompt, element ) {\n" - " var dlg = window.open( '', 'dialog', 'height=60,width=500' );\n" - " dlg.document.write(\n" - " '<form name=f1 onSubmit=\"opener.document.'\n" - " + element + '.value = goo.value; window.close(); " - "%s; return false;\">',\n" - " prompt, '<input type=password name=goo></form>' );\n" - " dlg.document.f1.goo.focus();\n" - " dlg.document.close();\n" - "}\n", otherJS ); - } - if ( ! inScript ) { - fprintf( stdout, "</SCRIPT>\n" ); - } -} - static int adm_initialized=0; /* Initialize NSPR for all the base functions we use */ @@ -1256,85 +234,3 @@ NSAPI_PUBLIC int ADM_Init(void) } return 0; } - - -#ifdef XP_UNIX -/* - * This function will return the SuiteSpot user id and group id used to - * recommend that Netscape Servers to run as. Any line starts with '#' - * is treated as comment. It looks for SuiteSpotUser/SuiteSpotGroup - * name/value pair. - * - * It returns 0 when success and allocate storage for user and group. - * returns -1 when only SuiteSpot user id is found. - * returns -2 when only SuiteSpot group id is found. - * returns -3 when NO SuiteSpot user and group is found. - * returns -4 when fails to open <server_root>/install/ssusers.conf - */ -NSAPI_PUBLIC int ADM_GetUXSSid(char *sroot, char **user, char **group) -{ - int foundUser, foundGroup; - char fn[BIG_LINE]; - char line[BIG_LINE]; - FILE *f; - - foundUser = 0; - foundGroup = 0; - *user = (char *) NULL; - *group = (char *) NULL; - - sprintf(fn, "%s/install/ssusers.conf", sroot); - if (f = fopen(fn, "r")) { - while (fgets(line, sizeof(line), f)) { - if (line[0] == '#') { - continue; - } - if (!strncmp(line, "SuiteSpotUser", strlen("SuiteSpotUser"))) { - char *ptr1; - ptr1 = line + strlen("SuiteSpotUser"); - while ((*ptr1 == '\t') || (*ptr1 == ' ')) { - ptr1++; - } - if ((strlen(ptr1) > 0) && (*user == (char *) NULL)) { - *user = (char *) MALLOC(strlen(ptr1)+1); - if (ptr1[strlen(ptr1)-1] == '\n') { - ptr1[strlen(ptr1)-1] = '\0'; - } - strcpy(*user, ptr1); - } - foundUser = 1; - continue; - } - if (!strncmp(line, "SuiteSpotGroup", strlen("SuiteSpotGroup"))) { - char *ptr1; - ptr1 = line + strlen("SuiteSpotGroup"); - while ((*ptr1 == '\t') || (*ptr1 == ' ')) { - ptr1++; - } - if ((strlen(ptr1) > 0) && (*group == (char *) NULL)) { - *group = (char *) MALLOC(strlen(ptr1)+1); - if (ptr1[strlen(ptr1)-1] == '\n') { - ptr1[strlen(ptr1)-1] = '\0'; - } - strcpy(*group, ptr1); - } - foundGroup = 1; - continue; - } - } - fclose(f); - } else { - return(-4); - } - - if (foundUser && foundGroup) { - return(0); - } else if (foundUser) { - return(-1); - } else if (foundGroup) { - return(-2); - } else { - return(-3); - } -} -#endif /* XP_UNIX */ diff --git a/lib/libsi18n/Makefile b/lib/libsi18n/Makefile index d9926bd5..c9fd4e7c 100644 --- a/lib/libsi18n/Makefile +++ b/lib/libsi18n/Makefile @@ -49,76 +49,17 @@ ifeq ($(ARCH), SOLARIS) MYLDFLAG = -xarch=v9 endif endif -ifeq ($(BUILD_MODULE), HTTP_ENTERPRISE) -StringDatabase = ns-httpd.db -L10N_SERVER = httpd -DBTheaders = \ - ../../httpd/src/dbthttpd.h \ - ../../include/base/dbtbase.h \ - ../../include/frame/dbtframe.h \ - ../../include/httpdaemon/dbthttpdaemon.h \ - ../../include/libaccess/dbtlibaccess.h \ - ../../include/libadmin/dbtlibadmin.h \ - ../../include/libir/dbtlibir.h \ - gshttpd.h -endif ifeq ($(BUILD_MODULE), DIRECTORY) StringDatabase = ns-slapd.properties DBTheaders = \ - ../../httpd/src/dbthttpd.h \ ../../include/base/dbtbase.h \ - ../../include/frame/dbtframe.h \ - ../../include/httpdaemon/dbthttpdaemon.h \ ../../include/libaccess/dbtlibaccess.h \ ../../include/libadmin/dbtlibadmin.h \ - ../../include/libir/dbtlibir.h \ ../../ldap/clients/dsgw/dbtdsgw.h \ gsslapd.h endif - -ifeq ($(BUILD_MODULE), HTTP_PERSONAL) -StringDatabase = ns-httpd.db -L10N_SERVER = httpd -DBTheaders = \ - ../../httpd/src/dbthttpd.h \ - ../../include/base/dbtbase.h \ - ../../include/frame/dbtframe.h \ - ../../include/httpdaemon/dbthttpdaemon.h \ - ../../include/libaccess/dbtlibaccess.h \ - ../../include/libadmin/dbtlibadmin.h \ - gshttpd.h -endif - -ifeq ($(BUILD_MODULE), HTTP_PROXY) -StringDatabase = ns-proxy.db -DBTheaders = \ - ../../httpd/src/dbthttpd.h \ - ../../include/base/dbtbase.h \ - ../../include/frame/dbtframe.h \ - ../../include/httpdaemon/dbthttpdaemon.h \ - ../../include/libaccess/dbtlibaccess.h \ - ../../include/libadmin/dbtlibadmin.h \ - gsproxy.h -endif - -ifeq ($(BUILD_MODULE), HTTP_ADMIN) -StringDatabase = ns-admin.db -L10N_SERVER = admserv -DBTheaders = \ - ../../admserv/src/dbtadmserv.h \ - ../../admserv/cgi-src/dbtcgiadmin.h \ - ../../admserv/user-forms/src/dbtuserforms.h \ - ../../include/base/dbtbase.h \ - ../../include/frame/dbtframe.h \ - ../../include/httpdaemon/dbthttpdaemon.h \ - ../../include/libaccess/dbtlibaccess.h \ - ../../include/libadmin/dbtlibadmin.h \ - ../../include/libir/dbtlibir.h \ - gsadmserv.h -endif - include $(BUILD_ROOT)/nsconfig.mk MCC_INCLUDE += $(ADMINUTIL_INCLUDE) diff --git a/lib/libsi18n/getlang.c b/lib/libsi18n/getlang.c index 5aa24d04..e5b4c998 100644 --- a/lib/libsi18n/getlang.c +++ b/lib/libsi18n/getlang.c @@ -11,7 +11,6 @@ #include <sys/stat.h> #include "libadmin/libadmin.h" -#include "frame/conf.h" /* get access on global language setting */ #include "i18n.h" diff --git a/lib/libsi18n/gsslapd.h b/lib/libsi18n/gsslapd.h index bbb44454..ccd73a5c 100644 --- a/lib/libsi18n/gsslapd.h +++ b/lib/libsi18n/gsslapd.h @@ -11,25 +11,16 @@ #undef LIBRARY_NAME #include "base/dbtbase.h" #undef LIBRARY_NAME -#include "frame/dbtframe.h" -#undef LIBRARY_NAME -#include "httpdaemon/dbthttpdaemon.h" -#undef LIBRARY_NAME #include "libaccess/dbtlibaccess.h" #undef LIBRARY_NAME #include "libadmin/dbtlibadmin.h" #undef LIBRARY_NAME -#include "libir/dbtlibir.h" -#undef LIBRARY_NAME #include "../ldap/clients/dsgw/dbtdsgw.h" static RESOURCE_GLOBAL allxpstr[] = { base, - frame, - httpdaemon, libaccess, libadmin, - libir, dsgw, 0 }; diff --git a/lib/libsi18n/makstrdb.c b/lib/libsi18n/makstrdb.c index 6f8b78dd..20155518 100644 --- a/lib/libsi18n/makstrdb.c +++ b/lib/libsi18n/makstrdb.c @@ -20,31 +20,11 @@ /* Begin: Application dependent information */ /********************************************/ -#ifdef MCC_ADMSERV -#include "gsadmserv.h" -#define GSXXX_H_INCLUDED -#endif - -#ifdef NS_ENTERPRISE -#include "gshttpd.h" -#define GSXXX_H_INCLUDED -#endif - #ifdef NS_DS #include "gsslapd.h" #define GSXXX_H_INCLUDED #endif -#ifdef NS_PERSONAL -#include "gshttpd.h" -#define GSXXX_H_INCLUDED -#endif - -#ifdef MCC_PROXY -#include "gsproxy.h" -#define GSXXX_H_INCLUDED -#endif - #ifdef buildAnotherServer #include "gsanother.h" #define GSXXX_H_INCLUDED |