Linux build compatible

Same source builds both in Linux and windows
This commit is contained in:
arif-pragmasys 2015-11-04 16:15:04 -06:00
parent 7683cc1f65
commit 9ec4bf235c
13 changed files with 122 additions and 64 deletions

View File

@ -37,8 +37,9 @@
*/
#include "includes.h"
#ifdef WIN32_FIXME
#include "xmalloc.h"
#endif
/*
* We support only client side kerberos on Windows.

View File

@ -4,12 +4,11 @@
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
/* Define if you have a getaddrinfo that fails for the all-zeros IPv6 address
/* Define if you have a getaddrinfo that fails for the all-zeros IPv6 address
*/
/* #undef AIX_GETNAMEINFO_HACK */
/* Define if your AIX loginfailed() function takes 4 arguments (AIX >= 5.2)
*/
/* Define if your AIX loginfailed() function takes 4 arguments (AIX >= 5.2) */
/* #undef AIX_LOGINFAILED_4ARG */
/* System only supports IPv4 audit records */
@ -30,7 +29,7 @@
/* FreeBSD glob does not do what we need */
/* #undef BROKEN_GLOB */
/* Define if you system's inet_ntoa is busted (e.g. Irix gcc issue) */
/* Define if you system's inet_ntoa is busted (e.g. Irix gcc issue) */
/* #undef BROKEN_INET_NTOA */
/* ia_uinfo routines not supported by OS yet */
@ -39,8 +38,8 @@
/* Ultrix mmap can't map files */
/* #undef BROKEN_MMAP */
/* Define if your struct dirent expects you to allocate extra space for
d_name */
/* Define if your struct dirent expects you to allocate extra space for d_name
*/
/* #undef BROKEN_ONE_BYTE_DIRENT_D_NAME */
/* Can't do comparisons on readv */
@ -94,19 +93,19 @@
/* Define if you want to specify the path to your wtmp file */
/* #undef CONF_WTMP_FILE */
/* Define if your platform needs to skip post auth file descriptor passing */
/* Define if your platform needs to skip post auth file descriptor passing */
#define DISABLE_FD_PASSING 1
/* Define if you don't want to use lastlog */
/* #undef DISABLE_LASTLOG */
/* Define if you don't want to use your system's login() call */
/* Define if you don't want to use your system's login() call */
/* #undef DISABLE_LOGIN */
/* Define if you don't want to use pututline() etc. to write [uw]tmp */
/* Define if you don't want to use pututline() etc. to write [uw]tmp */
/* #undef DISABLE_PUTUTLINE */
/* Define if you don't want to use pututxline() etc. to write [uw]tmpx */
/* Define if you don't want to use pututxline() etc. to write [uw]tmpx */
/* #undef DISABLE_PUTUTXLINE */
/* Define if you want to disable shadow passwords */
@ -142,22 +141,22 @@
/* Conflicting defs for getspnam */
/* #undef GETSPNAM_CONFLICTING_DEFS */
/* Define if your system glob() function has the GLOB_ALTDIRFUNC extension */
/* Define if your system glob() function has the GLOB_ALTDIRFUNC extension */
/* #undef GLOB_HAS_ALTDIRFUNC */
/* Define if your system glob() function has gl_matchc options in glob_t */
/* Define if your system glob() function has gl_matchc options in glob_t */
#define GLOB_HAS_GL_MATCHC 1
/* Define if your system glob() function has gl_statv options in glob_t */
/* Define if your system glob() function has gl_statv options in glob_t */
#define GLOB_HAS_GL_STATV 1
/* Define this if you want GSSAPI support in the version 2 protocol */
/* Define this if you want GSSAPI support in the version 2 protocol */
#define GSSAPI 1
/* Define if you want to use shadow password expire field */
/* #undef HAS_SHADOW_EXPIRE */
/* Define if your system uses access rights style file descriptor passing */
/* Define if your system uses access rights style file descriptor passing */
/* #undef HAVE_ACCRIGHTS_IN_MSGHDR */
/* Define if you have ut_addr in utmp.h */
@ -232,7 +231,7 @@
/* Define if gai_strerror() returns const char * */
/* #undef HAVE_CONST_GAI_STRERROR_PROTO */
/* Define if your system uses ancillary data style file descriptor passing */
/* Define if your system uses ancillary data style file descriptor passing */
/* #undef HAVE_CONTROL_IN_MSGHDR */
/* Define to 1 if you have the <crypto/sha2.h> header file. */
@ -673,7 +672,7 @@
/* Define to 1 if you have the `ogetaddrinfo' function. */
/* #undef HAVE_OGETADDRINFO */
/* Define if you have an old version of PAM which takes only one argument to
/* Define if you have an old version of PAM which takes only one argument to
pam_strerror */
/* #undef HAVE_OLD_PAM */
@ -683,11 +682,10 @@
/* Define to 1 if you have the `openpty' function. */
/* #undef HAVE_OPENPTY */
/* Define if your ssl headers are included with #include <openssl/header.h>
*/
/* Define if your ssl headers are included with #include <openssl/header.h> */
#define HAVE_OPENSSL 1
/* Define if you have Digital Unix Security Integration Architecture */
/* Define if you have Digital Unix Security Integration Architecture */
/* #undef HAVE_OSF_SIA */
/* Define to 1 if you have the `pam_getenvlist' function. */
@ -780,7 +778,7 @@
/* define if you have sa_family_t data type */
/* #undef HAVE_SA_FAMILY_T */
/* Define if you have SecureWare-based protected password database */
/* Define if you have SecureWare-based protected password database */
/* #undef HAVE_SECUREWARE */
/* Define to 1 if you have the <security/pam_appl.h> header file. */
@ -816,6 +814,9 @@
/* Define to 1 if you have the `setluid' function. */
/* #undef HAVE_SETLUID */
/* Define to 1 if you have the `setpassent' function. */
/* #undef HAVE_SETPASSENT */
/* Define to 1 if you have the `setpcred' function. */
/* #undef HAVE_SETPCRED */
@ -1218,13 +1219,13 @@
/* Define if compiler implements __func__ */
#define HAVE___func__ 1
/* Define this if you are using the Heimdal version of Kerberos V5 */
/* Define this if you are using the Heimdal version of Kerberos V5 */
/* #undef HEIMDAL */
/* Define if you need to use IP address instead of hostname in $DISPLAY */
/* Define if you need to use IP address instead of hostname in $DISPLAY */
/* #undef IPADDR_IN_DISPLAY */
/* Detect IPv4 in IPv6 mapped addresses and treat as IPv4 */
/* Detect IPv4 in IPv6 mapped addresses and treat as IPv4 */
/* #undef IPV4_IN_IPV6 */
/* Define if your system choked on IP TOS setting */
@ -1236,10 +1237,10 @@
/* Define if pututxline updates lastlog too */
/* #undef LASTLOG_WRITE_PUTUTXLINE */
/* Define if you want TCP Wrappers support */
/* Define if you want TCP Wrappers support */
/* #undef LIBWRAP */
/* Define to whatever link() returns for "not supported" if it doesn't return
/* Define to whatever link() returns for "not supported" if it doesn't return
EOPNOTSUPP. */
/* #undef LINK_OPNOTSUPP_ERRNO */
@ -1261,7 +1262,7 @@
/* String used in /etc/passwd to denote locked account */
/* #undef LOCKED_PASSWD_SUBSTR */
/* Some versions of /bin/login need the TERM supplied on the commandline */
/* Some versions of /bin/login need the TERM supplied on the commandline */
/* #undef LOGIN_NEEDS_TERM */
/* Some systems need a utmpx entry for /bin/login to work */
@ -1270,7 +1271,7 @@
/* Define if your login program cannot handle end of options ("--") */
/* #undef LOGIN_NO_ENDOPT */
/* If your header files don't define LOGIN_PROGRAM, then use this (detected)
/* If your header files don't define LOGIN_PROGRAM, then use this (detected)
from environment and PATH */
#define LOGIN_PROGRAM_FALLBACK "/usr/bin/login"
@ -1289,8 +1290,7 @@
/* Need setpgrp to acquire controlling tty */
/* #undef NEED_SETPGRP */
/* Define if the concept of ports only accessible to superusers isn't known
*/
/* Define if the concept of ports only accessible to superusers isn't known */
#define NO_IPPORT_RESERVED_CONCEPT 1
/* Define if you don't want to use lastlog in session.c */
@ -1329,8 +1329,8 @@
/* Define to the version of this package. */
#define PACKAGE_VERSION "Portable"
/* Define if you are using Solaris-derived PAM which passes pam_messages to
the conversation function with an extra level of indirection */
/* Define if you are using Solaris-derived PAM which passes pam_messages to
the conversation function with an extra level of indirection */
/* #undef PAM_SUN_CODEBASE */
/* Work around problematic Linux PAM modules handling of PAM_TTY */
@ -1381,20 +1381,20 @@
/* Define if you want S/Key support */
/* #undef SKEY */
/* Define if your skeychallenge() function takes 4 arguments (NetBSD) */
/* Define if your skeychallenge() function takes 4 arguments (NetBSD) */
/* #undef SKEYCHALLENGE_4ARG */
/* Define as const if snprintf() can declare const char *fmt */
#define SNPRINTF_CONST const
/* Define to a Set Process Title type if your system is supported by
/* Define to a Set Process Title type if your system is supported by
bsd-setproctitle.c */
/* #undef SPT_TYPE */
/* Define if sshd somehow reacquires a controlling TTY after setsid() */
/* Define if sshd somehow reacquires a controlling TTY after setsid() */
/* #undef SSHD_ACQUIRES_CTTY */
/* Define if pam_chauthtok wants real uid set to the unpriv'ed user */
/* Define if pam_chauthtok wants real uid set to the unpriv'ed user */
/* #undef SSHPAM_CHAUTHTOK_NEEDS_RUID */
/* Use audit debugging module */
@ -1427,7 +1427,7 @@
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you want a different $PATH for the superuser */
/* Define if you want a different $PATH for the superuser */
/* #undef SUPERUSER_PATH */
/* syslog_r function is safe to use in in a signal handler */
@ -1472,13 +1472,13 @@
/* Define if you have Solaris projects */
/* #undef USE_SOLARIS_PROJECTS */
/* Define if you shouldn't strip 'tty' from your ttyname in [uw]tmp */
/* Define if you shouldn't strip 'tty' from your ttyname in [uw]tmp */
/* #undef WITH_ABBREV_NO_TTY */
/* Define if you want to enable AIX4's authenticate function */
/* #undef WITH_AIXAUTHENTICATE */
/* Define if you have/want arrays (cluster-wide session managment, not C
/* Define if you have/want arrays (cluster-wide session managment, not C
arrays) */
/* #undef WITH_IRIX_ARRAY */

View File

@ -127,7 +127,11 @@
#if defined(HAVE_SECURITY_PAM_APPL_H)
# include <security/pam_appl.h>
#elif defined (HAVE_PAM_PAM_APPL_H)
#ifdef WIN32_FIXME
# include <security/pam_appl.h>
#else
# include <pam/pam_appl.h>
#endif
#endif
#endif
#ifdef HAVE_READPASSPHRASE_H

4
key.c
View File

@ -5,9 +5,7 @@
#include "includes.h"
#ifndef WIN32_FIXME
#include <openbsd-compat/openssl-compat.h>
#else
#ifdef WIN32_FIXME
#include "openbsd-compat/openssl-compat.h"
#endif

23
misc.c
View File

@ -545,7 +545,11 @@ char *
tilde_expand_filename(const char *filename, uid_t uid)
{
const char *path, *sep;
#ifdef WIN32_FIXME
char user[128], ret[MAXPATHLEN], *ret2;
#else
char user[128], *ret;
#endif
struct passwd *pw;
u_int len, slash;
@ -578,15 +582,9 @@ tilde_expand_filename(const char *filename, uid_t uid)
}
else if (snprintf(ret, sizeof(ret), "%ls", pw -> pw_dir) <= 0)
#else
if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
#endif
/* Make sure directory has a trailing '/' */
#ifdef WIN32_FIXME
// len = strlen(ret);
// if ((len == 0 || ret[len - 1] != '/') &&
// strlcat(ret, "/", sizeof(ret)) >= sizeof(ret))
#else
#ifndef WIN32_FIXME
len = strlen(pw->pw_dir);
if (len == 0 || pw->pw_dir[len - 1] != '/')
sep = "/";
@ -598,14 +596,17 @@ tilde_expand_filename(const char *filename, uid_t uid)
if (path != NULL)
filename = path + 1;
#ifdef WIN32_FIXME
if (xasprintf(&ret2, "%s%s", ret, filename) >= PATH_MAX)
#ifndef WIN32_FIXME
if (xasprintf(&ret, "%s%s%s", pw->pw_dir, sep, filename) >= PATH_MAX)
#else
if (xasprintf(&ret2, "%s%s%s", pw->pw_dir, sep, filename) >= PATH_MAX)
if (xasprintf(&ret2, "%s%s", ret, filename) >= PATH_MAX)
#endif
fatal("tilde_expand_filename: Path too long");
#ifdef WIN32_FIXME
return (ret2);
#else
return (ret);
#endif
}
/*

View File

@ -415,8 +415,10 @@ ssh_packet_connection_af(struct ssh *ssh)
if (getsockname(ssh->state->connection_out, (struct sockaddr *)&to,
&tolen) < 0)
return 0;
#ifdef WIN32_FIXME
if (to.ss_family == AF_INET)
return 1;
return 1;
#endif
#ifdef IPV4_IN_IPV6
if (to.ss_family == AF_INET6 &&
IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr))

View File

@ -382,9 +382,15 @@ clear_forwardings(Options *options)
options->tun_open = SSH_TUNMODE_NO;
}
#ifdef WIN32_FIXME
void
add_identity_file(Options *options, const char *dir, const char *filename,
int userprovided, struct passwd *pw)
#else
void
add_identity_file(Options *options, const char *dir, const char *filename,
int userprovided)
#endif
{
char *path;
int i;
@ -1004,8 +1010,13 @@ parse_time:
if (*intptr >= SSH_MAX_IDENTITY_FILES)
fatal("%.200s line %d: Too many identity files specified (max %d).",
filename, linenum, SSH_MAX_IDENTITY_FILES);
#ifdef WIN32_FIXME
add_identity_file(options, NULL,
arg, flags & SSHCONF_USERCONF, pw);
#else
add_identity_file(options, NULL,
arg, flags & SSHCONF_USERCONF);
#endif
}
break;
@ -1837,19 +1848,40 @@ void fill_default_options(Options * options, struct passwd *pw)
if (options->num_identity_files == 0) {
if (options->protocol & SSH_PROTO_1) {
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_IDENTITY, 0, pw);
#else
_PATH_SSH_CLIENT_IDENTITY, 0);
#endif
}
if (options->protocol & SSH_PROTO_2) {
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_RSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_RSA, 0);
#endif
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_DSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_DSA, 0);
#endif
#ifdef OPENSSL_HAS_ECC
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_ECDSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_ECDSA, 0);
#endif
#endif
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_ED25519, 0, pw);
#else
_PATH_SSH_CLIENT_ID_ED25519, 0);
#endif
}
}
if (options->escape_char == -1)

View File

@ -206,6 +206,10 @@ void dump_client_config(Options *o, const char *host);
void add_local_forward(Options *, const struct Forward *);
void add_remote_forward(Options *, const struct Forward *);
#ifdef WIN32_FIXME
void add_identity_file(Options *, const char *, const char *, int, struct passwd *);
#else
void add_identity_file(Options *, const char *, const char *, int);
#endif
#endif /* READCONF_H */

View File

@ -406,9 +406,11 @@ typedef enum {
sBadOption, /* == unknown option */
/* Portable-specific options */
sUsePAM,
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
sPAMLibrary,
#endif /* RUNTIME_LIBPAM */
#endif
/* Standard Options */
sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
@ -458,14 +460,18 @@ static struct {
/* Portable-specific options */
#ifdef USE_PAM
{ "usepam", sUsePAM, SSHCFG_GLOBAL },
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
{"pamlibrary", sPAMLibrary, SSHCFG_GLOBAL},
#endif /* RUNTIME_LIBPAM */
#endif
#else
{ "usepam", sUnsupported, SSHCFG_GLOBAL },
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
{"pamlibrary", sUnsupported, SSHCFG_GLOBAL},
#endif /* RUNTIME_LIBPAM */
#endif
#endif
{ "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
/* Standard Options */
@ -1028,6 +1034,7 @@ process_server_config_line(ServerOptions *options, char *line,
case sUsePAM:
intptr = &options->use_pam;
goto parse_flag;
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
/*
@ -1042,7 +1049,7 @@ process_server_config_line(ServerOptions *options, char *line,
}
#endif /* RUNTIME_LIBPAM */
#endif
/* Standard Options */
case sBadOption:
return -1;

View File

@ -201,9 +201,10 @@ typedef struct {
int fingerprint_hash;
#ifdef WIN32_FIXME
int i_am_a_fake_fork;
char *pamLibrary_;
#endif
char *pamLibrary_;
} ServerOptions;
/* Information about the incoming connection as used by Match */

View File

@ -1537,8 +1537,11 @@ main(int ac, char **av)
__progname = ssh_get_progname(av[0]);
seed_rng();
#ifdef WIN32_FIXME
while ((ch = getopt(ac, av, "cDdksE:a:t:f")) != -1) { // PRAGMA:TODO
#else
while ((ch = getopt(ac, av, "cDdksE:a:t:")) != -1) {
#endif
switch (ch) {
case 'E':
fingerprint_hash = ssh_digest_alg_by_name(optarg);

14
ssh.c
View File

@ -840,7 +840,11 @@ main(int ac, char **av)
strerror(errno));
break;
}
#ifdef WIN32_FIXME
add_identity_file(&options, NULL, optarg, 1, pw);
#else
add_identity_file(&options, NULL, optarg, 1);
#endif
break;
case 'I':
#ifdef ENABLE_PKCS11
@ -1469,7 +1473,7 @@ main(int ac, char **av)
_PATH_SSH_USER_DIR);
#else
r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
#endif
if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0) {
@ -1808,9 +1812,6 @@ ssh_session(void)
int interactive = 0;
int have_tty = 0;
struct winsize ws;
#ifndef WIN32_FIXME
struct winsize ws;
#endif
char *cp;
const char *display;
@ -2265,7 +2266,8 @@ load_public_identity_files(void)
explicit_bzero(pwdir, strlen(pwdir));
free(pwdir);
}
#ifdef SIGCHLD
#ifndef WIN32_FIXME
static void
main_sigchld_handler(int sig)
{
@ -2281,3 +2283,5 @@ main_sigchld_handler(int sig)
errno = save_errno;
}
#endif

3
ssh2.h
View File

@ -115,13 +115,14 @@
#define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
#define SSH2_MSG_USERAUTH_INFO_REQUEST 60
#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
#ifdef WIN32_FIXME
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_STEP1 60
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_STEP1 61
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_STEP2 62
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_STEP2 63
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_CONFIRM 64
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_CONFIRM 65
#endif
/* connection protocol: generic */
#define SSH2_MSG_GLOBAL_REQUEST 80