diff options
Diffstat (limited to 'adb/adb_auth_host.c')
-rw-r--r-- | adb/adb_auth_host.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/adb/adb_auth_host.c b/adb/adb_auth_host.c index c72fe42..a859199 100644 --- a/adb/adb_auth_host.c +++ b/adb/adb_auth_host.c @@ -15,9 +15,12 @@ */ #include <stdio.h> +#include <stdlib.h> #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include "windows.h" # include "shlobj.h" #else @@ -114,18 +117,34 @@ out: static void get_user_info(char *buf, size_t len) { char hostname[1024], username[1024]; - int ret; + int ret = -1; + + if (getenv("HOSTNAME") != NULL) { + strncpy(hostname, getenv("HOSTNAME"), sizeof(hostname)); + hostname[sizeof(hostname)-1] = '\0'; + ret = 0; + } #ifndef _WIN32 - ret = gethostname(hostname, sizeof(hostname)); if (ret < 0) + ret = gethostname(hostname, sizeof(hostname)); #endif + if (ret < 0) strcpy(hostname, "unknown"); + ret = -1; + + if (getenv("LOGNAME") != NULL) { + strncpy(username, getenv("LOGNAME"), sizeof(username)); + username[sizeof(username)-1] = '\0'; + ret = 0; + } + #if !defined _WIN32 && !defined ADB_HOST_ON_TARGET - ret = getlogin_r(username, sizeof(username)); if (ret < 0) + ret = getlogin_r(username, sizeof(username)); #endif + if (ret < 0) strcpy(username, "unknown"); ret = snprintf(buf, len, " %s@%s", username, hostname); @@ -436,6 +455,11 @@ int adb_auth_get_userkey(unsigned char *data, size_t len) return ret + 1; } +int adb_auth_keygen(const char* filename) { + adb_trace_mask |= (1 << TRACE_AUTH); + return (generate_key(filename) == 0); +} + void adb_auth_init(void) { int ret; |