mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-11 00:44:27 -05:00
8f2ff3eaf5
* Commandline Options added (./retroshare-nogui -h for help). * Added Password Hash system. * Shifted Menu output to std::string buffers. * Built interface to SSH server. * changed menus to lowercase. * Fixed SSH server restart issue. * Updates Output regularly now. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5398 b45a01b8-16f6-495d-af2f-9b41ad6348cc
140 lines
2.9 KiB
C++
140 lines
2.9 KiB
C++
/* This is a sample implementation of a libssh based SSH server */
|
|
/*
|
|
Copyright 2003-2009 Aris Adamantiadis
|
|
|
|
This file is part of the SSH Library
|
|
|
|
You are free to copy this file, modify it in any way, consider it being public
|
|
domain. This does not apply to the rest of the library though, but it is
|
|
allowed to cut-and-paste working code from this file to any license of
|
|
program.
|
|
The goal is to show the API in action. It's not a reference on how terminal
|
|
clients must be made or how a client should react.
|
|
*/
|
|
|
|
/*****
|
|
* Heavily Modified by Robert Fernie 2012... for retroshare project!
|
|
*
|
|
*/
|
|
|
|
|
|
#ifndef RS_SSHD_INTERFACE_H
|
|
#define RS_SSHD_INTERFACE_H
|
|
|
|
#include <libssh/libssh.h>
|
|
#include <libssh/server.h>
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
// From inside libretroshare.a
|
|
#include "util/rsthreads.h"
|
|
|
|
#include <string>
|
|
#include <map>
|
|
|
|
#include "rstermserver.h"
|
|
|
|
#ifndef KEYS_FOLDER
|
|
#ifdef _WIN32
|
|
#define KEYS_FOLDER
|
|
#else
|
|
#define KEYS_FOLDER "/etc/ssh/"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
/******
|
|
*
|
|
* Minimal Options to start with
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
//#define ALLOW_CLEARPWDS 1
|
|
|
|
class RsSshd;
|
|
extern RsSshd *rsSshd;
|
|
|
|
|
|
// TODO: NB: THIS FN DOES NOT USE A "SLOW" HASH FUNCTION.
|
|
// THE FIRST HALF OF THE HASH STRING IS THE SALT
|
|
int CheckPasswordHash(std::string pwdHashRadix64, std::string password);
|
|
int GeneratePasswordHash(std::string saltBin, std::string password, std::string &pwdHashRadix64);
|
|
int GenerateSalt(std::string &saltBin);
|
|
|
|
class RsSshd: public RsThread
|
|
{
|
|
public:
|
|
|
|
int adduserpwdhash(std::string username, std::string hash);
|
|
#ifdef ALLOW_CLEARPWDS
|
|
int adduser(std::string username, std::string password);
|
|
#endif // ALLOW_CLEARPWDS
|
|
|
|
|
|
|
|
virtual void run(); /* overloaded from RsThread => called once the thread is started */
|
|
|
|
// NB: This must be called EARLY before all the threads are launched.
|
|
static RsSshd *InitRsSshd(std::string portstr, std::string rsakeyfile);
|
|
|
|
// Terminal Handling!
|
|
int setTermServer(RsTermServer *s);
|
|
|
|
private:
|
|
RsSshd(std::string portStr); /* private constructor => so can only create with */
|
|
|
|
int init(std::string pathrsakey);
|
|
|
|
// High level operations.
|
|
int listenConnect();
|
|
int setupSession();
|
|
int interactive();
|
|
|
|
// Lower Level Operations.
|
|
int authUser();
|
|
int setupChannel();
|
|
int setupShell();
|
|
int doEcho();
|
|
|
|
// Terminal Handling!
|
|
int doTermServer();
|
|
|
|
int cleanupSession();
|
|
int cleanupAll();
|
|
|
|
/* Password Checking */
|
|
int auth_password(char *name, char *pwd);
|
|
int auth_password_hashed(char *name, char *pwd);
|
|
#ifdef ALLOW_CLEARPWDS
|
|
int auth_password_basic(char *name, char *pwd);
|
|
#endif // ALLOW_CLEARPWDS
|
|
|
|
// DATA.
|
|
|
|
RsMutex mSshMtx;
|
|
|
|
uint32_t mState;
|
|
uint32_t mBindState;
|
|
|
|
std::string mPortStr;
|
|
ssh_session mSession;
|
|
ssh_bind mBind;
|
|
ssh_channel mChannel;
|
|
|
|
RsTermServer *mTermServer;
|
|
#ifdef ALLOW_CLEARPWDS
|
|
std::map<std::string, std::string> mPasswords;
|
|
#endif // ALLOW_CLEARPWDS
|
|
std::map<std::string, std::string> mPwdHashs;
|
|
|
|
};
|
|
|
|
|
|
#endif
|
|
|