Commit a85e9197 authored by Steven Murray's avatar Steven Murray
Browse files

Removed the unused AuthXXXSocket classes

parent 93e907ee
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/Constants.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/IObject.hpp"
#include "castor/io/AuthClientSocket.hpp"
#include "castor/io/biniostream.h"
#include "castor/io/StreamAddress.hpp"
#include "castor/Services.hpp"
#include "net.h"
#include "serrno.h"
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::io::AuthClientSocket::AuthClientSocket(int socket)
:
ClientSocket(socket) {
if (loader() == -1) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "Dynamic library was not properly loaded";
throw ex;
}
if (getClient_initContext(&m_security_context, CSEC_SERVICE_TYPE_HOST, NULL) < 0) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "The initialization of the security context failed";
throw ex;
}
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::io::AuthClientSocket::AuthClientSocket(const unsigned short port,
const std::string host,
int)
: ClientSocket(port, host) {
if (loader() == -1) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "Dynamic library was not properly loaded";
throw ex;
}
if (getClient_initContext(&m_security_context, CSEC_SERVICE_TYPE_HOST, NULL) < 0) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "The initialization of the security context failed";
throw ex;
}
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::io::AuthClientSocket::AuthClientSocket(const unsigned short port,
const unsigned long ip,
int)
: ClientSocket(port, ip) {
if (loader() ==-1) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "Dynamic library was not properly loaded";
throw ex;
}
if (getClient_initContext(&m_security_context, CSEC_SERVICE_TYPE_HOST, NULL) < 0) {
castor::exception::Exception ex(serrno);
ex.getMessage() << "The initialization of the security context failed";
throw ex;
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::io::AuthClientSocket::~AuthClientSocket() throw() {
// Csec_clearContext(&m_security_context);
getClearContext(&m_security_context);
if (m_socket >= 0) {
::close(m_socket);
}
}
//------------------------------------------------------------------------------
// connect
//------------------------------------------------------------------------------
void castor::io::AuthClientSocket::connect()
{
castor::io::ClientSocket::connect();
if (getClient_establishContext(&m_security_context, m_socket) < 0) {
close();
castor::exception::Exception ex(serrno);
ex.getMessage() << "The initialization of the security context failed";
throw ex;
}
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Defines a dedicated socket that handles most of the network calls
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/exception/Exception.hpp"
#include "castor/io/ClientSocket.hpp"
#include "net.h"
extern "C" {
#include "Csecloader.h"
}
#include <string>
#include <netinet/in.h>
namespace castor {
// Forward declaration
class IObject;
namespace io {
/**
* A dedicated socket class, able to deal with socket manipulation
* and to handle sending and receiving of IObjects
*/
class AuthClientSocket : public ClientSocket {
public:
/**
* Constructor building a Socket objet around a regular socket
* @param socket the regular socket used
*/
AuthClientSocket(int socket) ;
/**
* Constructor building a socket on a given port of a given host
* @param port the port on which the socket should be opened on
* remote host
* @param host the host to connect to, given by its name
* @exception Exception in case of error
*/
AuthClientSocket(const unsigned short port,
const std::string host,
int service_type = CSEC_SERVICE_TYPE_HOST )
;
/**
* Constructor building a socket on a given port of a given host
* @param port the port on which the socket should be opened on
* remote host
* @param ip the host to connect to, given as an ip address
* @exception Exception in case of error
*/
AuthClientSocket(const unsigned short port,
const unsigned long ip,
int service_type = CSEC_SERVICE_TYPE_HOST )
;
/**
* Destructor
*/
~AuthClientSocket() throw();
/**
* Connects the socket to the given address
*/
virtual void connect()
;
protected:
Csec_context_t m_security_context;
};
} // end of namespace io
} // end of namespace castor
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/IObject.hpp"
#include "castor/io/AuthServerSocket.hpp"
#include "castor/Constants.hpp"
#include "castor/Services.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/io/biniostream.h"
#include "castor/io/StreamAddress.hpp"
#include "net.h"
#include "serrno.h"
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string>
castor::io::AuthServerSocket::AuthServerSocket(const unsigned short port,
const bool reusable)
: ServerSocket(port, reusable),
m_Euid(0), m_Egid(0) {
memset(&m_security_context, 0, sizeof(m_security_context));
}
//------------------------------------------------------------------------------
// constructor
// Initialize a AuthServerSocket from a ServerSocket. It copies the attributes
// of the ServerSocket, reuses the security context and establishes the context
// with the client and maps the user to a local user
//------------------------------------------------------------------------------
castor::io::AuthServerSocket::AuthServerSocket(castor::io::ServerSocket* cs,
const Csec_context_t)
: ServerSocket(cs->socket()),
m_Euid(0), m_Egid(0) {
memset(&m_security_context, 0, sizeof(m_security_context));
cs->resetSocket();
delete cs;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::io::AuthServerSocket::~AuthServerSocket() throw() {
getClearContext(&m_security_context);
}
//------------------------------------------------------------------------------
// accept
//------------------------------------------------------------------------------
castor::io::ServerSocket* castor::io::AuthServerSocket::accept()
{
castor::io::ServerSocket* as = castor::io::ServerSocket::accept();
return new AuthServerSocket(as, m_security_context);
}
//------------------------------------------------------------------------------
// setClientId (That method should go out of this class
//------------------------------------------------------------------------------
void castor::io::AuthServerSocket::setClientId ()
{
char *mech, *name;
char username[CA_MAXUSRNAMELEN+1];
// Returns the DN
getClientId(&m_security_context, &mech, &name);
// In the name you got the principal it in the previous call from the
// gridmapfile here you get uid and gid and if you want the name matching the
// uid then set buf and BUF_SIZE
if (getMapUser (mech, name, username, CA_MAXUSRNAMELEN, &m_Euid, &m_Egid) < 0) {
castor::exception::Security ex(serrno);
ex.getMessage() << "User cannot be mapped into local user";
throw ex;
}
m_secMech = mech;
m_userName = username;
}
//-----------------------------------------------------------------------------
// Init the security context and stablish the security context with the client
//-----------------------------------------------------------------------------
void castor::io::AuthServerSocket::initContext()
{
if (loader() == -1) {
castor::exception::Security ex(serrno);
ex.getMessage() << "Dynamic library was not properly loaded.";
throw ex;
}
if (getServer_initContext(&m_security_context, CSEC_SERVICE_TYPE_HOST, NULL) < 0) {
castor::exception::Security ex(ESEC_BAD_CREDENTIALS);
ex.getMessage() << "The initialization of the security context failed.";
throw ex;
}
if (getServer_establishContext(&m_security_context, m_socket) < 0) {
castor::exception::Security ex(ESEC_NO_CONTEXT);
ex.getMessage() << "The security context couldn't be established.";
throw ex;
}
}
//------------------------------------------------------------------------------
// getClientEuid
//------------------------------------------------------------------------------
uid_t castor::io::AuthServerSocket::getClientEuid () {
return m_Euid;
}
//------------------------------------------------------------------------------
// getClientEgid
//------------------------------------------------------------------------------
gid_t castor::io::AuthServerSocket::getClientEgid () {
return m_Egid;
}
//------------------------------------------------------------------------------
// getClientEgid
//------------------------------------------------------------------------------
std::string castor::io::AuthServerSocket::getClientMappedName () {
return m_userName;
}
//------------------------------------------------------------------------------
// getSecMech
//------------------------------------------------------------------------------
std::string castor::io::AuthServerSocket::getSecMech () {
return m_secMech;
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Defines a dedicated socket that handles most of the network calls
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/BaseObject.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/exception/Security.hpp"
#include "castor/io/ServerSocket.hpp"
#include "net.h"
extern "C" {
#include "Csecloader.h"
}
#include <string>
#include <netinet/in.h>
namespace castor {
// Forward declaration
class IObject;
namespace io {
/**
* A dedicated socket class, able to deal with socket manipulation
* and to handle sending and receiving of IObjects
*/
class AuthServerSocket : public ServerSocket {
public:
/**
* Constructor building a socket on a given local port
* @param port the local port for this socket. Use 0 if
* you want the system to allocate a port
* @param doListen whether to start listening on the socket.
*/
AuthServerSocket(const unsigned short port,
const bool reusable) ;
/**
*
*/
AuthServerSocket(castor::io::ServerSocket* cs,
const Csec_context_t context)
;
~AuthServerSocket() throw();
/**
* accept a connection and return the correponding Socket.
* The deallocation of the new socket is the responsability
* of the caller.
*/
virtual ServerSocket* accept() ;
/**
* This method gets the dn or principal of the client from the context and then
* map to a local user. If the local user doen't exist it throws and exception
* THAT METHOD SHOULDN'T BELONG TO THE CLASS SOCKET --TO BE MOVED
*/
void setClientId () ;
/**
* Returns the value uid in the local machine
* THAT METHOD SHOULDN'T BELONG TO THE CLASS SOCKET --TO BE MOVED
*/
uid_t getClientEuid ();
/**
* Returns the value guid in the local machine
* THAT METHOD SHOULDN'T BELONG TO THE CLASS SOCKET --TO BE MOVED
*/
gid_t getClientEgid ();
/**
* Returns the value user mmaped
* THAT METHOD SHOULDN'T BELONG TO THE CLASS SOCKET --TO BE MOVED
*/
std::string getClientMappedName();
/**
* Returns the value of the security mechanims used by the client
* THAT METHOD SHOULDN'T BELONG TO THE CLASS SOCKET --TO BE MOVED
*/
std::string getSecMech();
void initContext() ;
private:
Csec_context_t m_security_context;
uid_t m_Euid;
gid_t m_Egid;
std::string m_userName;
std::string m_secMech;
};
} // end of namespace io
} // end of namespace castor
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment