RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
User.hpp
1 /*
2  * User.hpp
3  *
4  * Copyright (C) 2022 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_USER_HPP
25 #define LAUNCHER_PLUGINS_USER_HPP
26 
27 #include <string>
28 #include <unistd.h>
29 
30 #include <PImpl.hpp>
31 
32 namespace rstudio {
33 namespace launcher_plugins {
34 
35 class Error;
36 
37 namespace system {
38 
39 class FilePath;
40 
41 } // namespace system
42 } // namespace launcher_plugins
43 } // namespace rstudio
44 
45 namespace rstudio {
46 namespace launcher_plugins {
47 namespace system {
48 
49 typedef uid_t UidType;
50 typedef gid_t GidType;
51 
55 class User
56 {
57 public:
58 
67  static FilePath getUserHomePath(const std::string& in_envOverride = std::string());
68 
77  explicit User(bool in_isEmpty = false);
78 
84  User(const User& in_other);
85 
91  User(User&& in_other) noexcept = default;
92 
101  static Error getCurrentUser(User& out_currentUser);
102 
111  static Error getUserFromIdentifier(const std::string& in_username, User& out_user);
112 
121  static Error getUserFromIdentifier(UidType in_userId, User& out_user);
122 
130  User& operator=(const User& in_other);
131 
139  User& operator=(User&& in_other) noexcept = default;
140 
148  bool operator==(const User& in_other) const;
149 
157  bool operator!=(const User& in_other) const;
158 
167  bool exists() const;
168 
174  bool isAllUsers() const;
175 
181  bool isEmpty() const;
182 
188  const FilePath& getHomePath() const;
189 
195  GidType getGroupId() const;
196 
202  const std::string& getShell() const;
203 
210  const std::string& getRealName() const;
211 
217  UidType getUserId() const;
218 
224  const std::string& getUsername() const;
225 
226 private:
227  // The private implementation of User.
228  PRIVATE_IMPL(m_impl);
229 };
230 
231 } // namesapce system
232 } // namespace launcher_plugins
233 } // namespace rstudio
234 
235 #endif
rstudio::launcher_plugins::system::FilePath
Class which represents a path on the system. May be any type of file (e.g. directory,...
Definition: FilePath.hpp:77
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::system::User::User
User(bool in_isEmpty=false)
Constructor.
rstudio::launcher_plugins::system::User::getHomePath
const FilePath & getHomePath() const
Gets the user home path, if it exists.
rstudio::launcher_plugins::system::User::operator==
bool operator==(const User &in_other) const
Equality operator.
rstudio::launcher_plugins::system::User::operator=
User & operator=(const User &in_other)
Overloaded assignment operator.
rstudio::launcher_plugins::system::User::getUserHomePath
static FilePath getUserHomePath(const std::string &in_envOverride=std::string())
Gets the user home path, as set in the environment.
rstudio::launcher_plugins::system::User::getShell
const std::string & getShell() const
Returns the login shell of this user.
rstudio::launcher_plugins::system::User::getUserId
UidType getUserId() const
Gets the ID of this user.
rstudio::launcher_plugins::system::User::getGroupId
GidType getGroupId() const
Gets the ID of this user's primary group.
rstudio::launcher_plugins::system::User::exists
bool exists() const
Checks whether the user represented by this object exists.
rstudio::launcher_plugins::system::User::getCurrentUser
static Error getCurrentUser(User &out_currentUser)
Gets the current user.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::system::User::isAllUsers
bool isAllUsers() const
Returns whether this object represents all users or not. See the default constructor for more details...
rstudio::launcher_plugins::system::User::getRealName
const std::string & getRealName() const
Returns the user's real name ("John Doe", not "jdoe")
rstudio::launcher_plugins::system::User::getUsername
const std::string & getUsername() const
Returns the name of this user.
rstudio::launcher_plugins::system::User::isEmpty
bool isEmpty() const
Checks whether this user is empty or not.
rstudio::launcher_plugins::system::User::getUserFromIdentifier
static Error getUserFromIdentifier(const std::string &in_username, User &out_user)
Gets a user from its username.
rstudio::launcher_plugins::system::User::operator!=
bool operator!=(const User &in_other) const
Inequality operator.