From 9ec4bf235c7afd908cc33e65d17ded984db17958 Mon Sep 17 00:00:00 2001 From: arif-pragmasys Date: Wed, 4 Nov 2015 16:15:04 -0600 Subject: [PATCH] Linux build compatible Same source builds both in Linux and windows --- auth-passwd.c | 3 +- config.h | 78 +++++++++++++++++++++++++-------------------------- includes.h | 4 +++ key.c | 4 +-- misc.c | 23 +++++++-------- packet.c | 4 ++- readconf.c | 32 +++++++++++++++++++++ readconf.h | 4 +++ servconf.c | 9 +++++- servconf.h | 3 +- ssh-agent.c | 5 +++- ssh.c | 14 +++++---- ssh2.h | 3 +- 13 files changed, 122 insertions(+), 64 deletions(-) diff --git a/auth-passwd.c b/auth-passwd.c index 81e1f99..d846b01 100644 --- a/auth-passwd.c +++ b/auth-passwd.c @@ -37,8 +37,9 @@ */ #include "includes.h" - +#ifdef WIN32_FIXME #include "xmalloc.h" +#endif /* * We support only client side kerberos on Windows. diff --git a/config.h b/config.h index 6263001..906cb4f 100644 --- a/config.h +++ b/config.h @@ -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 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 - */ +/* Define if your ssl headers are included with #include */ #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 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 */ diff --git a/includes.h b/includes.h index aba441a..7bc7fb6 100644 --- a/includes.h +++ b/includes.h @@ -127,7 +127,11 @@ #if defined(HAVE_SECURITY_PAM_APPL_H) # include #elif defined (HAVE_PAM_PAM_APPL_H) +#ifdef WIN32_FIXME # include +#else +# include +#endif #endif #endif #ifdef HAVE_READPASSPHRASE_H diff --git a/key.c b/key.c index 910ea1a..a66feb3 100644 --- a/key.c +++ b/key.c @@ -5,9 +5,7 @@ #include "includes.h" -#ifndef WIN32_FIXME -#include -#else +#ifdef WIN32_FIXME #include "openbsd-compat/openssl-compat.h" #endif diff --git a/misc.c b/misc.c index 0031f02..f9a6efd 100644 --- a/misc.c +++ b/misc.c @@ -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 } /* diff --git a/packet.c b/packet.c index 9dbff2c..dd6984e 100644 --- a/packet.c +++ b/packet.c @@ -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)) diff --git a/readconf.c b/readconf.c index f74bf70..8e3639b 100644 --- a/readconf.c +++ b/readconf.c @@ -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) diff --git a/readconf.h b/readconf.h index 6ae35c8..b2f17bf 100644 --- a/readconf.h +++ b/readconf.h @@ -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 */ diff --git a/servconf.c b/servconf.c index 499c779..ba710b3 100644 --- a/servconf.c +++ b/servconf.c @@ -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; diff --git a/servconf.h b/servconf.h index b306cfc..0c0ce5f 100644 --- a/servconf.h +++ b/servconf.h @@ -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 */ diff --git a/ssh-agent.c b/ssh-agent.c index 1454c29..2e4079f 100644 --- a/ssh-agent.c +++ b/ssh-agent.c @@ -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); diff --git a/ssh.c b/ssh.c index bce49d3..0eb4cd1 100644 --- a/ssh.c +++ b/ssh.c @@ -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 + + diff --git a/ssh2.h b/ssh2.h index 51a963c..6e55fe8 100644 --- a/ssh2.h +++ b/ssh2.h @@ -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