Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Credentials.h
17  * Handle getting and setting a process's credentials.
18  * Copyright (C) 2012 Simon Newton
19  */
20 
33 #ifndef INCLUDE_OLA_BASE_CREDENTIALS_H_
34 #define INCLUDE_OLA_BASE_CREDENTIALS_H_
35 
36 #include <unistd.h>
37 #include <string>
38 
39 namespace ola {
40 
45 using std::string;
46 
47 // These functions wrap their POSIX counterparts.
48 
58 uid_t GetUID();
59 
64 uid_t GetEUID();
65 
73 bool SetUID(uid_t new_uid);
74 
86 gid_t GetGID();
87 
92 gid_t GetEGID();
93 
101 bool SetGID(gid_t new_gid);
102 
111 typedef struct {
113  string pw_name;
114 
116  string pw_passwd; // no passwd for now
117 
119  uid_t pw_uid;
120 
122  gid_t pw_gid;
123 
125  string pw_dir;
126 
128  string pw_shell;
129 } PasswdEntry;
130 
147 bool GetPasswdName(const string &name, PasswdEntry *passwd);
148 
159 bool GetPasswdUID(uid_t uid, PasswdEntry *passwd);
160 
169 typedef struct {
171  string gr_name;
176  string gr_passwd; // no passwd for now
178  gid_t gr_gid;
179  // vector<string> gr_mem; // no members for now
180 } GroupEntry;
181 
197 bool GetGroupName(const string &name, GroupEntry *passwd);
198 
209 bool GetGroupGID(gid_t gid, GroupEntry *passwd);
214 } // namespace ola
215 #endif // INCLUDE_OLA_BASE_CREDENTIALS_H_