Bugzilla – Attachment 2156 Details for
Bug 2012
build for Android platform
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
android: basic support
0001-android-basic-support.patch (text/plain), 11.84 KB, created by
Roumen Petrov
on 2012-05-26 05:33:06 AEST
(
hide
)
Description:
android: basic support
Filename:
MIME Type:
Creator:
Roumen Petrov
Created:
2012-05-26 05:33:06 AEST
Size:
11.84 KB
patch
obsolete
>From 755349803feea86222ad10e2ee5f8b3fdcf3a134 Mon Sep 17 00:00:00 2001 >From: Roumen Petrov <openssh@roumenpetrov.info> >Date: Fri, 30 Mar 2012 23:50:00 +0300 >Subject: [PATCH 1/2] android: basic support > >--- > auth-passwd.c | 7 +++++ > auth.c | 2 + > configure.ac | 57 ++++++++++++++++++++++++++++++++++++--- > defines.h | 7 +++++ > loginrec.c | 10 +++++++ > misc.c | 2 + > monitor.c | 2 + > monitor_wrap.c | 2 + > openbsd-compat/bsd-closefrom.c | 23 ++++++++++++++++ > session.c | 32 ++++++++++++++++++++++ > sshd.c | 32 ++++++++++++++++++++++ > 11 files changed, 171 insertions(+), 5 deletions(-) > >diff --git a/auth-passwd.c b/auth-passwd.c >index 68bbd18..a44b005 100644 >--- a/auth-passwd.c >+++ b/auth-passwd.c >@@ -205,6 +205,13 @@ sys_auth_passwd(Authctxt *authctxt, const char *password) > encrypted_password = xcrypt(password, > (pw_password[0] && pw_password[1]) ? pw_password : "xx"); > >+#if defined(__ANDROID__) >+ /* FIXME: By default android does not support passwords >+ * Avoid crash in strcmp if password is not present >+ */ >+ if (!encrypted_password) >+ return (0); >+#endif > /* > * Authentication is accepted if the encrypted passwords > * are identical. >diff --git a/auth.c b/auth.c >index a8cffd5..f440793 100644 >--- a/auth.c >+++ b/auth.c >@@ -684,7 +684,9 @@ fakepw(void) > fake.pw_name = "NOUSER"; > fake.pw_passwd = > "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK"; >+#ifdef HAVE_STRUCT_PASSWD_PW_GECOS > fake.pw_gecos = "NOUSER"; >+#endif > fake.pw_uid = privsep_pw == NULL ? (uid_t)-1 : privsep_pw->pw_uid; > fake.pw_gid = privsep_pw == NULL ? (gid_t)-1 : privsep_pw->pw_gid; > #ifdef HAVE_PW_CLASS_IN_PASSWD >diff --git a/configure.ac b/configure.ac >index 17b2558..a0a129a 100644 >--- a/configure.ac >+++ b/configure.ac >@@ -357,7 +357,6 @@ AC_CHECK_HEADERS([ \ > sys/sysmacros.h \ > sys/time.h \ > sys/timers.h \ >- sys/un.h \ > time.h \ > tmpdir.h \ > ttyent.h \ >@@ -371,6 +370,11 @@ AC_CHECK_HEADERS([ \ > vis.h \ > ]) > >+# sys/un.h requires sys/socket.h to be included first on Android >+AC_CHECK_HEADERS([sys/un.h], [], [], [ >+#include <sys/socket.h> >+]) >+ > # lastlog.h requires sys/time.h to be included first on Solaris > AC_CHECK_HEADERS([lastlog.h], [], [], [ > #ifdef HAVE_SYS_TIME_H >@@ -667,9 +671,23 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) > AC_DEFINE([LINK_OPNOTSUPP_ERRNO], [EPERM], > [Define to whatever link() returns for "not supported" > if it doesn't return EOPNOTSUPP.]) >+ case "$host" in >+ *-*-linux-android*) : >+ ;; >+ *) > AC_DEFINE([_PATH_BTMP], ["/var/log/btmp"], [log for bad login attempts]) > AC_DEFINE([USE_BTMP]) >+ ;; >+ esac > AC_DEFINE([LINUX_OOM_ADJUST], [1], [Adjust Linux out-of-memory killer]) >+ case "$host" in >+ *-*-linux-android*) >+ AC_DEFINE([MISSING_HOWMANY], [1], [Define on *nto-qnx systems]) >+ AC_DEFINE([MISSING_FD_MASK], [1], [Define on *nto-qnx systems]) >+ SSHDLIBS="$SSHDLIBS -llog" >+ ;; >+ esac >+ > inet6_default_4in6=yes > case `uname -r` in > 1.*|2.0.*) >@@ -1768,12 +1786,21 @@ AC_CHECK_FUNC([daemon], > [LIBS="$LIBS -lbsd"; AC_DEFINE([HAVE_DAEMON])])] > ) > >+case "$host" in >+*-*-linux-android*) >+ dnl inline function on Android >+ AC_DEFINE([HAVE_GETPAGESIZE], [1], >+ [Define if your libraries define getpagesize()]) >+ ;; >+*) > AC_CHECK_FUNC([getpagesize], > [AC_DEFINE([HAVE_GETPAGESIZE], [1], > [Define if your libraries define getpagesize()])], > [AC_CHECK_LIB([ucb], [getpagesize], > [LIBS="$LIBS -lucb"; AC_DEFINE([HAVE_GETPAGESIZE])])] > ) >+ ;; >+esac > > # Check for broken snprintf > if test "x$ac_cv_func_snprintf" = "xyes" ; then >@@ -2931,8 +2958,13 @@ AC_CHECK_TYPES([fsblkcnt_t, fsfilcnt_t], , , [ > #endif > ]) > >+dnl on Android netinet/in.h define __in_addr_t and arpa/inet.h define in_addr_t >+AC_CHECK_HEADERS([arpa/inet.h]) > AC_CHECK_TYPES([in_addr_t, in_port_t], , , > [#include <sys/types.h> >+#ifdef HAVE_ARPA_INET_H >+#include <arpa/inet.h> >+#endif > #include <netinet/in.h>]) > > AC_CACHE_CHECK([for size_t], ac_cv_have_size_t, [ >@@ -3186,6 +3218,7 @@ if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then > [Fields in struct sockaddr_storage]) > fi > >+AC_CHECK_MEMBERS([struct passwd.pw_gecos],,,[#include <pwd.h>]) > AC_CACHE_CHECK([for pw_class field in struct passwd], > ac_cv_have_pw_class_in_struct_passwd, [ > AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <pwd.h> ]], >@@ -4280,15 +4313,21 @@ AC_ARG_ENABLE([utmp], > fi > ] > ) >+ssh_disable_utmpx=no > AC_ARG_ENABLE([utmpx], > [ --disable-utmpx disable use of utmpx even if detected [no]], > [ >- if test "x$enableval" = "xno" ; then >- AC_DEFINE([DISABLE_UTMPX], [1], >- [Define if you don't want to use utmpx]) >- fi >+ ssh_disable_utmpx=$enableval > ] > ) >+if test no = $ac_cv_header_utmpx_h; then >+ dnl Always disable utmpx if missing header utmpx.h (Android) >+ ssh_disable_utmpx=yes >+fi >+if test yes = $ssh_disable_utmpx; then >+ AC_DEFINE([DISABLE_UTMPX], [1], >+ [Define if you don't want to use utmpx]) >+fi > AC_ARG_ENABLE([wtmp], > [ --disable-wtmp disable use of wtmp even if detected [no]], > [ >@@ -4414,6 +4453,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ > #ifdef HAVE_PATHS_H > # include <paths.h> > #endif >+/* Compatibility names for the strings of the canonical file names */ >+#ifndef UTMP_FILE >+#define UTMP_FILE _PATH_UTMP >+#endif > ]], [[ char *utmp = UTMP_FILE; ]])], > [ AC_MSG_RESULT([yes]) ], > [ AC_MSG_RESULT([no]) >@@ -4444,6 +4487,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ > #ifdef HAVE_PATHS_H > # include <paths.h> > #endif >+/* Compatibility names for the strings of the canonical file names */ >+#ifndef WTMP_FILE >+#define WTMP_FILE _PATH_WTMP >+#endif > ]], [[ char *wtmp = WTMP_FILE; ]])], > [ AC_MSG_RESULT([yes]) ], > [ AC_MSG_RESULT([no]) >diff --git a/defines.h b/defines.h >index 53f83a1..daffcad 100644 >--- a/defines.h >+++ b/defines.h >@@ -804,4 +804,11 @@ struct winsize { > # endif > #endif > >+/* Write by owner (BSD compatible) */ >+#ifndef S_IWRITE >+# ifdef S_IWUSR >+# define S_IWRITE S_IWUSR >+# endif >+#endif >+ > #endif /* _DEFINES_H */ >diff --git a/loginrec.c b/loginrec.c >index 32941c9..9de351b 100644 >--- a/loginrec.c >+++ b/loginrec.c >@@ -216,6 +216,16 @@ extern Buffer loginmsg; > /* pick the shortest string */ > #define MIN_SIZEOF(s1,s2) (sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2)) > >+#if defined(__ANDROID__) >+/* Android define only user process */ >+#ifndef DEAD_PROCESS >+# define DEAD_PROCESS USER_PROCESS >+#endif >+#ifndef LOGIN_PROCESS >+# define LOGIN_PROCESS USER_PROCESS >+#endif >+#endif >+ > /** > ** platform-independent login functions > **/ >diff --git a/misc.c b/misc.c >index a7a23dc..f6d6c8e 100644 >--- a/misc.c >+++ b/misc.c >@@ -206,7 +206,9 @@ pwcopy(struct passwd *pw) > > copy->pw_name = xstrdup(pw->pw_name); > copy->pw_passwd = xstrdup(pw->pw_passwd); >+#ifdef HAVE_STRUCT_PASSWD_PW_GECOS > copy->pw_gecos = xstrdup(pw->pw_gecos); >+#endif > copy->pw_uid = pw->pw_uid; > copy->pw_gid = pw->pw_gid; > #ifdef HAVE_PW_EXPIRE_IN_PASSWD >diff --git a/monitor.c b/monitor.c >index f73491d..d7cf381 100644 >--- a/monitor.c >+++ b/monitor.c >@@ -762,7 +762,9 @@ mm_answer_pwnamallow(int sock, Buffer *m) > buffer_put_string(m, pwent, sizeof(struct passwd)); > buffer_put_cstring(m, pwent->pw_name); > buffer_put_cstring(m, "*"); >+#ifdef HAVE_STRUCT_PASSWD_PW_GECOS > buffer_put_cstring(m, pwent->pw_gecos); >+#endif > #ifdef HAVE_PW_CLASS_IN_PASSWD > buffer_put_cstring(m, pwent->pw_class); > #endif >diff --git a/monitor_wrap.c b/monitor_wrap.c >index 9bfda50..5235425 100644 >--- a/monitor_wrap.c >+++ b/monitor_wrap.c >@@ -259,7 +259,9 @@ mm_getpwnamallow(const char *username) > fatal("%s: struct passwd size mismatch", __func__); > pw->pw_name = buffer_get_string(&m, NULL); > pw->pw_passwd = buffer_get_string(&m, NULL); >+#ifdef HAVE_STRUCT_PASSWD_PW_GECOS > pw->pw_gecos = buffer_get_string(&m, NULL); >+#endif > #ifdef HAVE_PW_CLASS_IN_PASSWD > pw->pw_class = buffer_get_string(&m, NULL); > #endif >diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c >index 9380b33..0e9444c 100644 >--- a/openbsd-compat/bsd-closefrom.c >+++ b/openbsd-compat/bsd-closefrom.c >@@ -74,13 +74,36 @@ closefrom(int lowfd) > struct dirent *dent; > DIR *dirp; > int len; >+#ifdef __ANDROID__ >+ int pws_fd = -1; >+#endif > >+#ifdef __ANDROID__ >+{ >+ /* keep android property workspace open */ >+ char *pws_env = getenv("ANDROID_PROPERTY_WORKSPACE"); >+ if (pws_env) { >+ char *s, *q; >+ s = strdup(pws_env); >+ /* format "int,int" */ >+ q = strchr(s, ','); >+ if (q) { >+ q = '\0'; >+ pws_fd = atoi(s); >+ } >+ free(s); >+ } >+} >+#endif > /* Check for a /proc/$$/fd directory. */ > len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); > if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { > while ((dent = readdir(dirp)) != NULL) { > fd = strtol(dent->d_name, &endp, 10); > if (dent->d_name != endp && *endp == '\0' && >+ #ifdef __ANDROID__ >+ (fd != pws_fd) && >+ #endif > fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp)) > (void) close((int) fd); > } >diff --git a/session.c b/session.c >index 65bf287..5b941c9 100644 >--- a/session.c >+++ b/session.c >@@ -1203,6 +1203,33 @@ do_setup_env(Session *s, const char *shell) > if (getenv("TZ")) > child_set_env(&env, &envsize, "TZ", getenv("TZ")); > >+#ifdef __ANDROID__ >+{ >+#define COPY_ANDROID_ENV(name) { \ >+ char *s = getenv(name); \ >+ if (s) child_set_env(&env, &envsize, name, s); } >+ >+ /* from /init.rc */ >+ COPY_ANDROID_ENV("ANDROID_BOOTLOGO"); >+ COPY_ANDROID_ENV("ANDROID_ROOT"); >+ COPY_ANDROID_ENV("ANDROID_ASSETS"); >+ COPY_ANDROID_ENV("ANDROID_DATA"); >+ COPY_ANDROID_ENV("ASEC_MOUNTPOINT"); >+ COPY_ANDROID_ENV("LOOP_MOUNTPOINT"); >+ COPY_ANDROID_ENV("BOOTCLASSPATH"); >+ >+ /* FIXME: keep android property workspace open >+ * (see openbsd-compat/bsd-closefrom.c) >+ */ >+ COPY_ANDROID_ENV("ANDROID_PROPERTY_WORKSPACE"); >+ >+ COPY_ANDROID_ENV("EXTERNAL_STORAGE"); /* ??? */ >+ COPY_ANDROID_ENV("SD_EXT_DIRECTORY"); /* ??? */ >+ >+#undef COPY_ANDROID_ENV >+} >+#endif >+ > /* Set custom environment options from RSA authentication. */ > if (!options.use_login) { > while (custom_environment) { >@@ -1496,7 +1523,12 @@ do_setusercontext(struct passwd *pw) > perror("initgroups"); > exit(1); > } >+ #if !defined(__ANDROID__) >+ /* FIXME: function is not defined in bionic (Android) >+ * TODO: add function check to confugure >+ */ > endgrent(); >+ #endif > #endif > > platform_setusercontext_post_groups(pw); >diff --git a/sshd.c b/sshd.c >index ef04642..68e5bf2 100644 >--- a/sshd.c >+++ b/sshd.c >@@ -260,6 +260,34 @@ Buffer loginmsg; > /* Unprivileged user */ > struct passwd *privsep_pw = NULL; > >+#ifdef __ANDROID__ >+ >+#include <android/log.h> >+ >+static void >+android_log(LogLevel level, const char *msg, void *ctx) { >+ android_LogPriority a; >+ >+ (void)ctx; >+ >+ switch (level) { >+ case SYSLOG_LEVEL_QUIET : a = ANDROID_LOG_SILENT ; break; >+ case SYSLOG_LEVEL_FATAL : a = ANDROID_LOG_FATAL ; break; >+ case SYSLOG_LEVEL_ERROR : a = ANDROID_LOG_ERROR ; break; >+ case SYSLOG_LEVEL_INFO : a = ANDROID_LOG_WARN ; break; >+ case SYSLOG_LEVEL_VERBOSE : a = ANDROID_LOG_INFO ; break; >+ case SYSLOG_LEVEL_DEBUG1 : a = ANDROID_LOG_DEBUG ; break; >+ case SYSLOG_LEVEL_DEBUG2 : a = ANDROID_LOG_DEBUG ; break; >+ case SYSLOG_LEVEL_DEBUG3 : a = ANDROID_LOG_VERBOSE ; break; >+ default : a = ANDROID_LOG_UNKNOWN ; break; >+ } >+ >+ if (a != ANDROID_LOG_UNKNOWN) >+ __android_log_write(a, __progname, msg); >+} >+ >+#endif >+ > /* Prototypes for various functions defined later in this file. */ > void destroy_sensitive_data(void); > void demote_sensitive_data(void); >@@ -1777,6 +1805,10 @@ main(int ac, char **av) > } > /* Reinitialize the log (because of the fork above). */ > log_init(__progname, options.log_level, options.log_facility, log_stderr); >+#ifdef __ANDROID__ >+ if (!log_stderr) >+ set_log_handler(android_log, NULL); >+#endif > > /* Initialize the random number generator. */ > arc4random_stir(); >-- >1.7.4.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2012
: 2156 |
2157