Open Lighting Architecture: include/ola/base/Credentials.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
Credentials.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Credentials.h
17 * Handle getting and setting a process's credentials.
18 * Copyright (C) 2012 Simon Newton
19 */
20
32
33#ifndef INCLUDE_OLA_BASE_CREDENTIALS_H_
34#define INCLUDE_OLA_BASE_CREDENTIALS_H_
35
36#include <unistd.h>
37#include <string>
38
39#ifdef _WIN32
40#ifndef uid_t
41#define uid_t int
42#endif // uid_t
43#ifndef gid_t
44#define gid_t int
45#endif // gid_t
46#endif // _WIN32
47
48namespace ola {
49
54
55// These functions wrap their POSIX counterparts.
56
61
66bool SupportsUIDs();
67
73bool GetUID(uid_t* uid);
74
80bool GetEUID(uid_t* euid);
81
89bool SetUID(uid_t new_uid);
90
97
103bool GetGID(gid_t* gid);
104
110bool GetEGID(gid_t* egid);
111
119bool SetGID(gid_t new_gid);
120
127
128
137int GetGroups(int size, gid_t list[]);
138
145bool SetGroups(size_t size, const gid_t *list);
146
150
155 typedef struct {
157 std::string pw_name;
158
160 std::string pw_passwd; // no passwd for now
161
163 uid_t pw_uid;
164
166 gid_t pw_gid;
167
169 std::string pw_dir;
170
172 std::string pw_shell;
173} PasswdEntry;
174
179
191bool GetPasswdName(const std::string &name, PasswdEntry *passwd);
192
203bool GetPasswdUID(uid_t uid, PasswdEntry *passwd);
204
208
213 typedef struct {
215 std::string gr_name;
220 std::string gr_passwd; // no passwd for now
222 gid_t gr_gid;
223 // vector<string> gr_mem; // no members for now
224} GroupEntry;
225
230
241bool GetGroupName(const std::string &name, GroupEntry *passwd);
242
253bool GetGroupGID(gid_t gid, GroupEntry *passwd);
258} // namespace ola
259#endif // INCLUDE_OLA_BASE_CREDENTIALS_H_
ola::GetPasswdUID
bool GetPasswdUID(uid_t uid, PasswdEntry *passwd)
Lookup a user account by UID.
Definition Credentials.cpp:258
ola::GetEGID
bool GetEGID(gid_t *egid)
Get the effective group ID.
Definition Credentials.cpp:106
ola::SetGroups
bool SetGroups(size_t size, const gid_t *list)
Set the supplementary group ID's of the process.
Definition Credentials.cpp:158
ola::GetEUID
bool GetEUID(uid_t *euid)
Get the effective UID of the process.
Definition Credentials.cpp:76
ola::GetGroupName
bool GetGroupName(const string &name, GroupEntry *group_entry)
Lookup a group account by name.
Definition Credentials.cpp:336
ola::GetGroups
int GetGroups(int size, gid_t list[])
Get the supplementary group ID's of the process.
Definition Credentials.cpp:148
ola::GetGroupGID
bool GetGroupGID(gid_t gid, GroupEntry *group_entry)
Lookup a group account by GID.
Definition Credentials.cpp:351
ola::GetGID
bool GetGID(gid_t *gid)
Get the real Group ID.
Definition Credentials.cpp:91
ola::SetGID
bool SetGID(gid_t new_gid)
Set the effective Group ID of the process.
Definition Credentials.cpp:135
ola::SetUID
bool SetUID(uid_t new_uid)
Set the effective UID of the process.
Definition Credentials.cpp:121
ola::GetPasswdName
bool GetPasswdName(const string &name, PasswdEntry *passwd)
Lookup a user account by username.
Definition Credentials.cpp:243
ola::SupportsUIDs
bool SupportsUIDs()
Check whether the current platform supports User and Group IDs.
Definition Credentials.cpp:53
ola::GetUID
bool GetUID(uid_t *uid)
Get the real UID of the process.
Definition Credentials.cpp:61
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::GroupEntry
Contains information about a group.
Definition Credentials.h:213
ola::GroupEntry::gr_name
std::string gr_name
name of the group
Definition Credentials.h:215
ola::GroupEntry::gr_gid
gid_t gr_gid
Group ID.
Definition Credentials.h:222
ola::GroupEntry::gr_passwd
std::string gr_passwd
password for the group
Definition Credentials.h:220
ola::PasswdEntry
Contains information about a user.
Definition Credentials.h:155
ola::PasswdEntry::pw_gid
gid_t pw_gid
real Group ID
Definition Credentials.h:166
ola::PasswdEntry::pw_dir
std::string pw_dir
user's home directory
Definition Credentials.h:169
ola::PasswdEntry::pw_passwd
std::string pw_passwd
Unused currently.
Definition Credentials.h:160
ola::PasswdEntry::pw_uid
uid_t pw_uid
real User ID
Definition Credentials.h:163
ola::PasswdEntry::pw_name
std::string pw_name
name of the user
Definition Credentials.h:157
ola::PasswdEntry::pw_shell
std::string pw_shell
user's shell program
Definition Credentials.h:172