second part of win32 changes
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@143 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
0d6e3c1790
Коммит
c284eb4e38
33
Makefile.Windows
Обычный файл
33
Makefile.Windows
Обычный файл
@ -0,0 +1,33 @@
|
||||
CC= gcc
|
||||
INCS= -I. -Iinclude -Ic:/progra~1/gnuwin32/include
|
||||
CFLAGS= $(INCS)
|
||||
LINK= -L. -Lc:/progra~1/gnuwin32/lib -lws2_32 -lcrypto -lgdi32 -lshell32 -lz
|
||||
|
||||
libssh_HEADERS= config.h include/libssh/crypto.h include/libssh/libssh.h include/libssh/priv.h include/libssh/server.h include/libssh/sftp.h include/libssh/ssh1.h include/libssh/ssh2.h
|
||||
libssh_OBJS = libssh/auth1.o libssh/auth.o libssh/base64.o libssh/buffer.o \
|
||||
libssh/channels1.o libssh/channels.o libssh/client.o libssh/connect.o \
|
||||
libssh/crc32.o libssh/crypt.o libssh/dh.o libssh/error.o libssh/gcrypt_missing.o \
|
||||
libssh/gzip.o libssh/init.o libssh/kex.o libssh/keyfiles.o \
|
||||
libssh/keys.o libssh/messages.o libssh/misc.o libssh/options.o \
|
||||
libssh/packet.o libssh/server.o libssh/session.o libssh/sftp.o \
|
||||
libssh/sftpserver.o libssh/string.o libssh/wrapper.o libssh/socket.o
|
||||
|
||||
|
||||
all: libssh.dll samplesshd.exe
|
||||
|
||||
config.h: config.h.win32-openssl
|
||||
copy config.h.win32-openssl config.h
|
||||
|
||||
%.o: %.c $(libssh_HEADERS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
sample.exe: sample.o $(libssh_OBJS)
|
||||
$(CC) $< -o $@ $(libssh_OBJS) $(LINK)
|
||||
samplesshd.exe: samplesshd.o $(libssh_OBJS)
|
||||
$(CC) $< -o $@ $(libssh_OBJS) $(LINK)
|
||||
|
||||
libssh.dll: $(libssh_OBJS)
|
||||
$(CC) -shared $(libssh_OBJS) -o libssh.dll $(LINK)
|
||||
|
||||
clean:
|
||||
rm -f $(libssh_OBJS) samplesshd.exe sample.exe libssh.dll config.h
|
193
config.h.win32-openssl
Обычный файл
193
config.h.win32-openssl
Обычный файл
@ -0,0 +1,193 @@
|
||||
/* config.h. Manually tweaked for Windows. */
|
||||
|
||||
/* Define to 1 if you have the `cfmakeraw' function. */
|
||||
#define HAVE_CFMAKERAW 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define to 1 if you have the `endpwent' function. */
|
||||
/* #undef HAVE_ENDPWENT */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <gcrypt.h> header file. */
|
||||
/* #undef HAVE_GCRYPT_H */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname' function. */
|
||||
#define HAVE_GETHOSTBYNAME 1
|
||||
|
||||
/* Define to 1 if you have the `getpass' function. */
|
||||
/* #undef HAVE_GETPASS */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
|
||||
/* #undef HAVE_LIBGCRYPT */
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
/* #undef HAVE_NETDB_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
/* #undef HAVE_NETINET_IN_H */
|
||||
|
||||
/* Define to 1 if you have the <openssl/aes.h> header file. */
|
||||
#define HAVE_OPENSSL_AES_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/blowfish.h> header file. */
|
||||
#define HAVE_OPENSSL_BLOWFISH_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/des.h> header file. */
|
||||
#define HAVE_OPENSSL_DES_H 1
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
/* #undef HAVE_POLL */
|
||||
|
||||
/* Define to 1 if you have the <pty.h> header file. */
|
||||
/* #undef HAVE_PTY_H */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||
and to 0 otherwise. */
|
||||
#define HAVE_REALLOC 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you want to enable SSH1 */
|
||||
/* #undef HAVE_SSH1 */
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strchr' function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strstr' function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define to 1 if you have the <sys/poll.h> header file. */
|
||||
/* #undef HAVE_SYS_POLL_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <termios.h> header file. */
|
||||
/* #undef HAVE_TERMIOS_H */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <zlib.h> header file. */
|
||||
#define HAVE_ZLIB_H 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libssh"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "aris@0xbadc0de.be"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libssh"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libssh 0.2"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libssh"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "0.2"
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (fd_set *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.2"
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
/* #undef realloc */
|
@ -222,7 +222,7 @@ struct ssh_options_struct {
|
||||
char *identity;
|
||||
char *ssh_dir;
|
||||
char *known_hosts_file;
|
||||
int fd; /* specificaly wanted file descriptor, don't connect host */
|
||||
socket_t fd; /* specificaly wanted file descriptor, don't connect host */
|
||||
int port;
|
||||
int dont_verify_hostkey; /* Don't spare time, don't check host key ! unneeded to say it's dangerous and not safe */
|
||||
int use_nonexisting_algo; /* if user sets a not supported algorithm for kex, don't complain */
|
||||
@ -370,7 +370,7 @@ struct ssh_kbdint {
|
||||
|
||||
struct ssh_bind_struct {
|
||||
struct error_struct error;
|
||||
int bindfd;
|
||||
socket_t bindfd;
|
||||
SSH_OPTIONS *options;
|
||||
int blocking;
|
||||
int toaccept;
|
||||
@ -425,10 +425,11 @@ struct ssh_message {
|
||||
/* socketc.c */
|
||||
|
||||
struct socket;
|
||||
void ssh_socket_init();
|
||||
struct socket *ssh_socket_new();
|
||||
void ssh_socket_free(struct socket *s);
|
||||
void ssh_socket_set_fd(struct socket *s, int fd);
|
||||
int ssh_socket_get_fd(struct socket *s);
|
||||
void ssh_socket_set_fd(struct socket *s, socket_t fd);
|
||||
socket_t ssh_socket_get_fd(struct socket *s);
|
||||
void ssh_socket_close(struct socket *s);
|
||||
int ssh_socket_read(struct socket *s, void *buffer, int len);
|
||||
int ssh_socket_write(struct socket *s,const void *buffer, int len);
|
||||
|
@ -235,6 +235,7 @@ int ssh_connect(SSH_SESSION *session){
|
||||
session->alive=0;
|
||||
session->client=1;
|
||||
ssh_crypto_init();
|
||||
ssh_socket_init();
|
||||
if(options->fd==-1 && !options->host){
|
||||
ssh_set_error(session,SSH_FATAL,"Hostname required");
|
||||
return SSH_ERROR;
|
||||
|
@ -22,6 +22,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include "libssh/priv.h"
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
int ssh_finalize()
|
||||
{
|
||||
@ -30,6 +33,9 @@ int ssh_finalize()
|
||||
gcry_control(GCRYCTL_TERM_SECMEM);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
EVP_cleanup();
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,11 +24,20 @@ MA 02111-1307, USA. */
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_IE 0x0400 //SHGetSpecialFolderPath
|
||||
#include <shlobj.h>
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
/* if the program was executed suid root, don't trust the user ! */
|
||||
static int is_trusted(){
|
||||
if(geteuid()!=getuid())
|
||||
@ -77,6 +86,18 @@ char *ssh_get_user_home_dir(){
|
||||
return get_homedir_from_uid(getuid());
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
char *ssh_get_user_home_dir(){
|
||||
static char szPath[MAX_PATH];
|
||||
if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE))
|
||||
return szPath;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* we have read access on file */
|
||||
int ssh_file_readaccess_ok(char *file){
|
||||
if(!access(file,R_OK))
|
||||
|
@ -23,7 +23,9 @@ MA 02111-1307, USA. */
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include "libssh/priv.h"
|
||||
|
||||
@ -176,7 +178,7 @@ void ssh_options_set_username(SSH_OPTIONS *opt, char *username){
|
||||
* \param opt options structure
|
||||
* \param fd an opened file descriptor to use
|
||||
*/
|
||||
void ssh_options_set_fd(SSH_OPTIONS *opt, int fd){
|
||||
void ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd){
|
||||
opt->fd=fd;
|
||||
}
|
||||
|
||||
@ -289,6 +291,7 @@ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){
|
||||
struct passwd *pwd;
|
||||
char *user;
|
||||
@ -303,6 +306,7 @@ static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){
|
||||
ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* this function must be called when no specific username has been asked. it has to guess it */
|
||||
int ssh_options_default_username(SSH_OPTIONS *opt){
|
||||
@ -314,11 +318,23 @@ int ssh_options_default_username(SSH_OPTIONS *opt){
|
||||
opt->username=strdup(user);
|
||||
return 0;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
user=get_username_from_uid(opt,getuid());
|
||||
if(user){
|
||||
opt->username=user;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
DWORD Size = 0;
|
||||
GetUserName(NULL, &Size); //Get Size
|
||||
user = malloc(Size);
|
||||
if (GetUserName(user, &Size)){
|
||||
opt->username=user;
|
||||
return 0;
|
||||
} else {
|
||||
free(user);
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,7 @@ int ssh_bind_listen(SSH_BIND *ssh_bind){
|
||||
int fd;
|
||||
if(!ssh_bind->options)
|
||||
return -1;
|
||||
ssh_socket_init();
|
||||
host=ssh_bind->options->bindaddr;
|
||||
if(!host)
|
||||
host="0.0.0.0";
|
||||
|
@ -35,7 +35,18 @@ struct socket {
|
||||
int last_errno;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* \internal
|
||||
* \brief inits the socket system (windows specific)
|
||||
*/
|
||||
void ssh_socket_init(){
|
||||
#ifdef _WIN32
|
||||
struct WSAData wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
|
||||
ssh_say(1,"Error initialising Windows sockets.\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* \internal
|
||||
* \brief creates a new Socket object
|
||||
|
@ -25,6 +25,11 @@ MA 02111-1307, USA. */
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#ifdef _WIN32
|
||||
#define KEYS_FOLDER
|
||||
#else
|
||||
#define KEYS_FOLDER "/etc/ssh/"
|
||||
#endif
|
||||
|
||||
int auth_password(char *user, char *password){
|
||||
if(strcmp(user,"aris"))
|
||||
@ -114,7 +119,7 @@ int main(int argc, char **argv){
|
||||
} while(message && !chan);
|
||||
if(!chan){
|
||||
printf("error : %s\n",ssh_get_error(session));
|
||||
ssh_finalize();
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user