libDwm-0.9.45
DwmPassword.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2006-2007, 2016
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMPASSWORD_HH_
42#define _DWMPASSWORD_HH_
43
44extern "C" {
45#include <sys/types.h>
46#include <pwd.h>
47}
48
49#include <iostream>
50#include <mutex>
51#include <string>
52
53namespace Dwm {
54
55 //--------------------------------------------------------------------------
59 //--------------------------------------------------------------------------
61 {
62 public:
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
66 Password(const std::string & userName);
67
68 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
71 Password(uid_t userId);
72
73 //------------------------------------------------------------------------
75 //------------------------------------------------------------------------
76 void Set(const struct passwd & passwdStruct);
77
78 //------------------------------------------------------------------------
80 //------------------------------------------------------------------------
81 const std::string & UserName() const;
82
83 //------------------------------------------------------------------------
85 //------------------------------------------------------------------------
86 const std::string & EncryptedPassword() const;
87
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 uid_t UserId() const;
92
93 //------------------------------------------------------------------------
95 //------------------------------------------------------------------------
96 gid_t GroupId() const;
97
98 //------------------------------------------------------------------------
100 //------------------------------------------------------------------------
101 const std::string & Gecos() const;
102
103 //------------------------------------------------------------------------
105 //------------------------------------------------------------------------
106 const std::string & HomeDirectory() const;
107
108 //------------------------------------------------------------------------
110 //------------------------------------------------------------------------
111 const std::string & Shell() const;
112
113 //------------------------------------------------------------------------
115 //------------------------------------------------------------------------
116 friend std::ostream & operator << (std::ostream & os,
117 const Password & password);
118
119 private:
120 std::string _userName;
121 std::string _encryptedPassword;
122 uid_t _userId;
123 gid_t _groupId;
124 std::string _gecos;
125 std::string _homeDirectory;
126 std::string _shell;
127
128 static std::mutex _mutex;
129 };
130
131} // namespace Dwm
132
133#endif // _DWMPASSWORD_HH_
134
135//---------------------------- emacs settings -----------------------------
136// Local Variables:
137// mode: C++
138// tab-width: 2
139// indent-tabs-mode: nil
140// c-basic-offset: 2
141// End:
142//-------------------------------------------------------------------------
Encapsulates an /etc/passwd entry.
Definition DwmPassword.hh:61
const std::string & Shell() const
Returns the shell.
friend std::ostream & operator<<(std::ostream &os, const Password &password)
Prints to an ostream in /etc/passwd format.
Password(uid_t userId)
Construct from a user ID.
const std::string & HomeDirectory() const
Returns the home directory.
const std::string & UserName() const
Returns the user name.
gid_t GroupId() const
Returns the group ID.
Password(const std::string &userName)
Construct from a user name.
const std::string & Gecos() const
Returns the gecos.
const std::string & EncryptedPassword() const
Returns the user password.
uid_t UserId() const
Returns the user ID.
void Set(const struct passwd &passwdStruct)
Use the contents of passwdStruct to fill all of our members.