From e5917b2d3067fe20087ed1901a1908b5cb4435a0 Mon Sep 17 00:00:00 2001 From: cantor Date: Wed, 6 Feb 2008 21:09:10 +0000 Subject: [PATCH] Bug fix, linefeed fix, move keygen to install hook and add script to dist. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2728 cb58f699-b61c-0410-a6fe-9272a202ed29 --- configs/Makefile.am | 21 ++- configs/keygen.sh | 64 +++---- shibsp/remoting/impl/UnixListener.cpp | 317 +++++++++++++++++----------------- 3 files changed, 203 insertions(+), 199 deletions(-) diff --git a/configs/Makefile.am b/configs/Makefile.am index 7b394e1..8b17cae 100644 --- a/configs/Makefile.am +++ b/configs/Makefile.am @@ -29,10 +29,10 @@ BUILTCONFIGFILES = \ # While BUILTCONFIGFILES are processed, these are not; so we should pull # them from SRCDIR. CONFIGFILES = \ - shibboleth2.xml \ - attribute-map.xml \ - attribute-policy.xml \ - example-metadata.xml \ + shibboleth2.xml \ + attribute-map.xml \ + attribute-policy.xml \ + example-metadata.xml \ console.logger \ syslog.logger \ accessError.html \ @@ -105,10 +105,12 @@ install-data-local: all-data-local fi; \ $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)${pkgsysconfdir}/$$f.dist; \ done - if test -z $NOKEYGEN ; then \ - cd $(DESTDIR)$(pkgsysconfdir); \ - sh ./keygen.sh -b ; \ - fi + +install-data-hook: + if test -z "$(NOKEYGEN)"; then \ + cd $(DESTDIR)$(pkgsysconfdir); \ + sh ./keygen.sh -b ; \ + fi CLEANFILES = \ apache.config \ @@ -129,5 +131,6 @@ EXTRA_DIST = \ shibd-redhat.in \ shibd-debian.in \ shibd-osx.plist.in \ - keygen.bat \ + keygen.bat \ + keygen.sh \ $(CONFIGFILES) diff --git a/configs/keygen.sh b/configs/keygen.sh index 0096d42..f1f4076 100755 --- a/configs/keygen.sh +++ b/configs/keygen.sh @@ -1,32 +1,32 @@ -#! /bin/sh - -while getopts h:y:b c - do - case $c in - b) BATCH=1;; - h) FQDN=$OPTARG;; - y) DAYS=$OPTARG;; - \?) echo keygen [-h hostname/cn for cert] [-y years to issue cert] - exit 1;; - esac - done - -if [ -e sp-key.pem ] || [ -e sp-cert.pem ] ; then - if [ -z $BATCH ] ; then - echo The files sp-key.pem and/or sp-cert.pem already exist! - exit 2 - fi - exit 0 -fi - -if [ -z $FQDN ] ; then - FQDN=`hostname` -fi - -if [ -z $DAYS ] ; then - DAYS=10 -fi - -DAYS=$(($DAYS*365)) - -openssl req -x509 -days $DAYS -newkey rsa:2048 -nodes -keyout sp-key.pem -out sp-cert.pem -subj /CN=$FQDN -extensions usr_cert -set_serial 0 +#! /bin/sh + +while getopts h:y:b c + do + case $c in + b) BATCH=1;; + h) FQDN=$OPTARG;; + y) DAYS=$OPTARG;; + \?) echo keygen [-h hostname/cn for cert] [-y years to issue cert] + exit 1;; + esac + done + +if [ -e sp-key.pem ] || [ -e sp-cert.pem ] ; then + if [ -z $BATCH ] ; then + echo The files sp-key.pem and/or sp-cert.pem already exist! + exit 2 + fi + exit 0 +fi + +if [ -z $FQDN ] ; then + FQDN=`hostname` +fi + +if [ -z $DAYS ] ; then + DAYS=10 +fi + +DAYS=$(($DAYS*365)) + +openssl req -x509 -days $DAYS -newkey rsa:2048 -nodes -keyout sp-key.pem -out sp-cert.pem -subj /CN=$FQDN -extensions usr_cert -set_serial 0 diff --git a/shibsp/remoting/impl/UnixListener.cpp b/shibsp/remoting/impl/UnixListener.cpp index 7004287..1180e27 100644 --- a/shibsp/remoting/impl/UnixListener.cpp +++ b/shibsp/remoting/impl/UnixListener.cpp @@ -1,158 +1,159 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * UnixListener.cpp - * - * Unix Domain-based SocketListener implementation - */ - -#include "internal.h" -#include "remoting/impl/SocketListener.h" - -#include -#include -#include - -#ifdef HAVE_UNISTD_H -# include -# include -# include -# include -#endif - -#include -#include /* for chmod() */ -#include -#include -#include - -using namespace shibsp; -using namespace xmltooling; -using namespace xercesc; -using namespace std; - - -namespace shibsp { - static const XMLCh address[] = UNICODE_LITERAL_7(a,d,d,r,e,s,s); - - class UnixListener : virtual public SocketListener - { - public: - UnixListener(const DOMElement* e); - ~UnixListener() {if (m_bound) unlink(m_address.c_str());} - - bool create(ShibSocket& s) const; - bool bind(ShibSocket& s, bool force=false) const; - bool connect(ShibSocket& s) const; - bool close(ShibSocket& s) const; - bool accept(ShibSocket& listener, ShibSocket& s) const; - - int send(ShibSocket& s, const char* buf, int len) const { - return ::send(s, buf, len, 0); - } - - int recv(ShibSocket& s, char* buf, int buflen) const { - return ::recv(s, buf, buflen, 0); - } - - private: - string m_address; - mutable bool m_bound; - }; - - ListenerService* SHIBSP_DLLLOCAL UnixListenerServiceFactory(const DOMElement* const & e) - { - return new UnixListener(e); - } -}; - -UnixListener::UnixListener(const DOMElement* e) : SocketListener(e), m_address("/var/run/shar-socket"), m_bound(false) -{ - const XMLCh* tag=e->getAttributeNS(NULL,address); - if (tag && *tag) { - auto_ptr_char a(tag); - m_address=a.get(); - XMLToolingConfig::getConfig().getPathResolver()->resolve(m_address, PathResolver::XMLTOOLING_RUN_FILE); - } -} - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 100 -#endif - -bool UnixListener::create(ShibSocket& sock) const -{ - sock = socket(PF_UNIX, SOCK_STREAM, 0); - if (sock < 0) - return log_error(); - return true; -} - -bool UnixListener::bind(ShibSocket& s, bool force) const -{ - struct sockaddr_un addr; - memset(&addr, 0, sizeof (addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, m_address.c_str(), UNIX_PATH_MAX); - - if (force) - unlink(m_address.c_str()); - - if (::bind(s, (struct sockaddr *)&addr, sizeof (addr)) < 0) { - log_error(); - close(s); - return false; - } - - // Make sure that only the creator can read -- we don't want just - // anyone connecting, do we? - if (chmod(m_address.c_str(),0777) < 0) { - log_error(); - close(s); - unlink(m_address.c_str()); - return false; - } - - listen(s, 3); - return m_bound=true; -} - -bool UnixListener::connect(ShibSocket& s) const -{ - struct sockaddr_un addr; - memset(&addr, 0, sizeof (addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, m_address.c_str(), UNIX_PATH_MAX); - - if (::connect(s, (struct sockaddr *)&addr, sizeof (addr)) < 0) - return log_error(); - return true; -} - -bool UnixListener::close(ShibSocket& s) const -{ - ::close(s); - return true; -} - -bool UnixListener::accept(ShibSocket& listener, ShibSocket& s) const -{ - s=::accept(listener,NULL,NULL); - if (s < 0) - return log_error(); - return true; -} +/* + * Copyright 2001-2007 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * UnixListener.cpp + * + * Unix Domain-based SocketListener implementation + */ + +#include "internal.h" +#include "remoting/impl/SocketListener.h" + +#include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +# include +# include +# include +#endif + +#include +#include /* for chmod() */ +#include +#include +#include + +using namespace shibsp; +using namespace xmltooling; +using namespace xercesc; +using namespace std; + + +namespace shibsp { + static const XMLCh address[] = UNICODE_LITERAL_7(a,d,d,r,e,s,s); + + class UnixListener : virtual public SocketListener + { + public: + UnixListener(const DOMElement* e); + ~UnixListener() {if (m_bound) unlink(m_address.c_str());} + + bool create(ShibSocket& s) const; + bool bind(ShibSocket& s, bool force=false) const; + bool connect(ShibSocket& s) const; + bool close(ShibSocket& s) const; + bool accept(ShibSocket& listener, ShibSocket& s) const; + + int send(ShibSocket& s, const char* buf, int len) const { + return ::send(s, buf, len, 0); + } + + int recv(ShibSocket& s, char* buf, int buflen) const { + return ::recv(s, buf, buflen, 0); + } + + private: + string m_address; + mutable bool m_bound; + }; + + ListenerService* SHIBSP_DLLLOCAL UnixListenerServiceFactory(const DOMElement* const & e) + { + return new UnixListener(e); + } +}; + +UnixListener::UnixListener(const DOMElement* e) : SocketListener(e), m_address("/var/run/shar-socket"), m_bound(false) +{ + const XMLCh* tag=e->getAttributeNS(NULL,address); + if (tag && *tag) { + auto_ptr_char a(tag); + m_address=a.get(); + XMLToolingConfig::getConfig().getPathResolver()->resolve(m_address, PathResolver::XMLTOOLING_RUN_FILE); + } +} + +#ifndef UNIX_PATH_MAX +#define UNIX_PATH_MAX 100 +#endif + +bool UnixListener::create(ShibSocket& sock) const +{ + sock = socket(PF_UNIX, SOCK_STREAM, 0); + if (sock < 0) + return log_error(); + return true; +} + +bool UnixListener::bind(ShibSocket& s, bool force) const +{ + struct sockaddr_un addr; + memset(&addr, 0, sizeof (addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, m_address.c_str(), UNIX_PATH_MAX); + + if (force) + unlink(m_address.c_str()); + + if (::bind(s, (struct sockaddr *)&addr, sizeof (addr)) < 0) { + log_error(); + close(s); + return false; + } + + // Make sure that only the creator can read -- we don't want just + // anyone connecting, do we? + if (chmod(m_address.c_str(),0777) < 0) { + log_error(); + close(s); + unlink(m_address.c_str()); + return false; + } + + listen(s, 3); + return m_bound=true; +} + +bool UnixListener::connect(ShibSocket& s) const +{ + struct sockaddr_un addr; + memset(&addr, 0, sizeof (addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, m_address.c_str(), UNIX_PATH_MAX); + + if (::connect(s, (struct sockaddr *)&addr, sizeof (addr)) < 0) + return log_error(); + return true; +} + +bool UnixListener::close(ShibSocket& s) const +{ + ::close(s); + return true; +} + +bool UnixListener::accept(ShibSocket& listener, ShibSocket& s) const +{ + s=::accept(listener,NULL,NULL); + if (s < 0) + return log_error(); + return true; +} -- 2.1.4