diff options
-rw-r--r-- | remoting/base/util.cc | 25 | ||||
-rw-r--r-- | remoting/base/util.h | 4 | ||||
-rw-r--r-- | remoting/host/pam_authorization_factory_posix.cc | 2 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 2 | ||||
-rw-r--r-- | remoting/host/username.cc | 36 | ||||
-rw-r--r-- | remoting/host/username.h | 18 | ||||
-rw-r--r-- | remoting/remoting.gyp | 8 |
7 files changed, 61 insertions, 34 deletions
diff --git a/remoting/base/util.cc b/remoting/base/util.cc index d27b651..8102cb9 100644 --- a/remoting/base/util.cc +++ b/remoting/base/util.cc @@ -14,12 +14,6 @@ #include "third_party/libyuv/include/libyuv/convert.h" #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" -#if defined(OS_POSIX) -#include <pwd.h> -#include <sys/types.h> -#include <unistd.h> -#endif // defined(OS_POSIX) - using media::VideoFrame; namespace remoting { @@ -313,25 +307,6 @@ bool StringIsUtf8(const char* data, size_t length) { return true; } -std::string GetUsername() { -#if defined(OS_ANDROID) - struct passwd* passwd = getpwuid(getuid()); - return passwd ? passwd->pw_name : std::string(); -#elif defined(OS_POSIX) - long buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); - if (buf_size <= 0) - return std::string(); - - scoped_ptr<char[]> buf(new char[buf_size]); - struct passwd passwd; - struct passwd* passwd_result = NULL; - getpwuid_r(getuid(), &passwd, buf.get(), buf_size, &passwd_result); - return passwd_result ? passwd_result->pw_name : std::string(); -#else // !defined(OS_POSIX) - return std::string(); -#endif // defined(OS_POSIX) -} - bool DoesRectContain(const webrtc::DesktopRect& a, const webrtc::DesktopRect& b) { webrtc::DesktopRect intersection(a); diff --git a/remoting/base/util.h b/remoting/base/util.h index 5478c7f..c8c7021 100644 --- a/remoting/base/util.h +++ b/remoting/base/util.h @@ -93,10 +93,6 @@ std::string ReplaceCrLfByLf(const std::string& in); // Checks if the given string is a valid UTF-8 string. bool StringIsUtf8(const char* data, size_t length); -// Returns the username associated with this process, or the empty string on -// error or if not implemented. -std::string GetUsername(); - bool DoesRectContain(const webrtc::DesktopRect& a, const webrtc::DesktopRect& b); diff --git a/remoting/host/pam_authorization_factory_posix.cc b/remoting/host/pam_authorization_factory_posix.cc index 6488852..c89c71f 100644 --- a/remoting/host/pam_authorization_factory_posix.cc +++ b/remoting/host/pam_authorization_factory_posix.cc @@ -10,7 +10,7 @@ #include "base/callback.h" #include "base/environment.h" #include "remoting/base/logging.h" -#include "remoting/base/util.h" +#include "remoting/host/username.h" #include "remoting/protocol/channel_authenticator.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index ba5fc1b..bc7e8a7 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -36,7 +36,6 @@ #include "remoting/base/constants.h" #include "remoting/base/logging.h" #include "remoting/base/rsa_key_pair.h" -#include "remoting/base/util.h" #include "remoting/host/branding.h" #include "remoting/host/chromoting_host.h" #include "remoting/host/chromoting_host_context.h" @@ -67,6 +66,7 @@ #include "remoting/host/signaling_connector.h" #include "remoting/host/token_validator_factory_impl.h" #include "remoting/host/usage_stats_consent.h" +#include "remoting/host/username.h" #include "remoting/jingle_glue/network_settings.h" #include "remoting/jingle_glue/xmpp_signal_strategy.h" #include "remoting/protocol/me2me_host_authenticator_factory.h" diff --git a/remoting/host/username.cc b/remoting/host/username.cc new file mode 100644 index 0000000..e737425 --- /dev/null +++ b/remoting/host/username.cc @@ -0,0 +1,36 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/username.h" + +#include <vector> + +#include "base/logging.h" + +#if defined(OS_POSIX) +#include <pwd.h> +#include <sys/types.h> +#include <unistd.h> +#endif // defined(OS_POSIX) + +namespace remoting { + +std::string GetUsername() { +#if defined(OS_POSIX) + long buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); + if (buf_size <= 0) + return std::string(); + + std::vector<char> buf(buf_size); + struct passwd passwd; + struct passwd* passwd_result = NULL; + getpwuid_r(getuid(), &passwd, &(buf[0]), buf_size, &passwd_result); + return passwd_result ? passwd_result->pw_name : std::string(); +#else // !defined(OS_POSIX) + NOTIMPLEMENTED(); + return std::string(); +#endif // defined(OS_POSIX) +} + +} // namespace remoting diff --git a/remoting/host/username.h b/remoting/host/username.h new file mode 100644 index 0000000..28fc2ae --- /dev/null +++ b/remoting/host/username.h @@ -0,0 +1,18 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_HOST_USERNAME_H_ +#define REMOTING_HOST_USERNAME_H_ + +#include <string> + +namespace remoting { + +// Returns the username associated with this process, or the empty string on +// error or if not implemented. +std::string GetUsername(); + +} // namespace remoting + +#endif // REMOTING_HOST_USERNAME_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 44315d1..ae025ae 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -343,18 +343,18 @@ 'host/dns_blackhole_checker.h', 'host/heartbeat_sender.cc', 'host/heartbeat_sender.h', - 'host/host_status_sender.cc', - 'host/host_status_sender.h', 'host/host_change_notification_listener.cc', 'host/host_change_notification_listener.h', 'host/host_config.cc', 'host/host_config.h', - 'host/host_exit_codes.h', 'host/host_exit_codes.cc', + 'host/host_exit_codes.h', 'host/host_secret.cc', 'host/host_secret.h', 'host/host_status_monitor.h', 'host/host_status_observer.h', + 'host/host_status_sender.cc', + 'host/host_status_sender.h', 'host/host_window.h', 'host/host_window_proxy.cc', 'host/host_window_proxy.h', @@ -441,6 +441,8 @@ 'host/usage_stats_consent.h', 'host/usage_stats_consent_mac.cc', 'host/usage_stats_consent_win.cc', + 'host/username.cc', + 'host/username.h', 'host/video_scheduler.cc', 'host/video_scheduler.h', 'host/win/com_security.cc', |