1 martin 1.13 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.14 //
|
3 martin 1.13 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.14 //
|
10 martin 1.13 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.14 //
|
17 martin 1.13 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.14 //
|
20 martin 1.13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.13 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.14 //
|
28 martin 1.13 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%////////////////////////////////////////////////////////////////////////////
31
32
33 ///////////////////////////////////////////////////////////////////////////////
|
34 kumpf 1.11 //
35 // This file implements the functionality required to manage password file.
|
36 mike 1.2 //
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #ifndef Pegasus_UserFileHandler_h
40 #define Pegasus_UserFileHandler_h
41
42 #include <cctype>
43 #include <fstream>
44
45 #include <Pegasus/Common/Config.h>
|
46 a.arora 1.6 #include <Pegasus/Common/AutoPtr.h>
|
47 mike 1.10 #include <Pegasus/Common/Mutex.h>
|
48 mike 1.2
49 #include <Pegasus/Security/UserManager/PasswordFile.h>
50 #include <Pegasus/Security/UserManager/Linkage.h>
51
52 PEGASUS_NAMESPACE_BEGIN
53
54 /**
|
55 kumpf 1.11 This class implements the functionality required to manage password file.
|
56 mike 1.2 */
57
58 class PEGASUS_USERMANAGER_LINKAGE UserFileHandler
59 {
60
61 private:
62
63 //
|
64 kumpf 1.3 // Contains the property name for password filepath
|
65 mike 1.2 //
|
66 kumpf 1.11 static const String _PROPERTY_NAME_PASSWORD_FILEPATH;
|
67 mike 1.2
68 //
69 // Contains the salt string for password encryption
70 //
|
71 kumpf 1.11 static const unsigned char _SALT_STRING[];
|
72 mike 1.2
73 //
|
74 kumpf 1.3 // Denotes the types of update operations
75 //
76 enum UpdateOperations
77 {
|
78 kumpf 1.11 ADD_USER,
79 MODIFY_USER,
80 REMOVE_USER
|
81 kumpf 1.3 };
82
83 //
84 // Contains the mutex timeout value
85 //
|
86 kumpf 1.11 static const Uint32 _MUTEX_TIMEOUT;
|
87 mike 1.2
88 //
89 // Password cache
90 //
|
91 kumpf 1.11 PasswordTable _passwordTable;
|
92 mike 1.2
93 //
94 // Instance of the PasswordFile
95 //
|
96 kumpf 1.11 AutoPtr<PasswordFile> _passwordFile;
|
97 kumpf 1.3
98 //
99 // Mutex variable for consistent Password File and cache updates
100 //
|
101 kumpf 1.11 AutoPtr<Mutex> _mutex;
|
102 mike 1.2
103 /**
|
104 kumpf 1.11 Generate random salt key for password encryption
|
105 mike 1.2
|
106 kumpf 1.11 @param salt A array of 3 characters
|
107 mike 1.2 */
108 void _GetSalt (char* salt);
109
|
110 kumpf 1.3 /**
|
111 kumpf 1.11 Update the password hash table and write to password file
|
112 kumpf 1.3 */
113 void _Update(
|
114 kumpf 1.11 char operation,
115 const String& userName,
116 const String& password = String::EMPTY);
|
117 kumpf 1.3
118
|
119 mike 1.2 protected:
120
121 /**
|
122 kumpf 1.11 Load the user information from the password file.
|
123 mike 1.2
|
124 kumpf 1.11 @exception PasswordFileSyntaxError if password file contains a syntax
125 error.
126 @exception CannotRenameFile if password file cannot be renamed.
|
127 mike 1.2 */
|
128 kumpf 1.11 void _loadAllUsers();
|
129 mike 1.2
130 public:
131
132 /** Constructor. */
133 UserFileHandler();
134
135 /** Destructor. */
136 ~UserFileHandler();
|
137 kumpf 1.3
|
138 kumpf 1.11 /**
139 Add user entry to file
|
140 mike 1.2
|
141 kumpf 1.11 @param userName The name of the user to add.
142 @param password The password for the user.
|
143 mike 1.2
|
144 kumpf 1.11 @exception FileNotReadable if unable to read password file
145 @exception DuplicateUser if the user is already exists
146 @exception PasswordCacheError if there is an error processing
147 password hashtable
148 @exception CannotRenameFile if password file cannot be renamed.
149 */
150 void addUserEntry(
151 const String& userName,
|
152 kumpf 1.12 const String& password);
|
153 kumpf 1.11
154 /**
155 Modify user entry in file
156
157 @param userName The name of the user to modify.
158 @param password User's old password.
159 @param newPassword User's new password.
160
161 @exception InvalidUser if the user does not exist.
162 @exception PasswordMismatch if the specified password does not match
163 user's current password.
164 @exception PasswordCacheError if there is an error processing
165 password hashtable
166 @exception CannotRenameFile if password file cannot be renamed.
|
167 mike 1.2
168 */
169 void modifyUserEntry(
|
170 kumpf 1.11 const String& userName,
171 const String& password,
172 const String& newPassword);
173
174 /**
175 Remove user entry from file
176
177 @param userName The name of the user to add.
178
179 @exception FileNotReadable if unable to read password file
180 @exception InvalidUser if the user is does not exist
181 @exception PasswordCacheError if there is an error processing
182 password hashtable
183 @exception CannotRenameFile if password file cannot be renamed.
|
184 mike 1.2 */
185 void removeUserEntry(const String& userName);
186
187 /**
|
188 kumpf 1.11 Get a list of all the user names.
|
189 mike 1.2
|
190 kumpf 1.11 @param userNames List containing all the user names.
|
191 mike 1.2
|
192 kumpf 1.11 @exception FileNotReadable if unable to read password file
|
193 mike 1.2 */
194 void getAllUserNames(Array<String>& userNames);
195
196 /**
|
197 kumpf 1.11 Verify user exists in the cimserver password file
|
198 mike 1.2
|
199 kumpf 1.11 @param userName Name of the user to be verified
200 @return true if the user exists, else false
|
201 mike 1.2
|
202 kumpf 1.11 @exception FileNotReadable if unable to read password file
|
203 mike 1.2 */
204 Boolean verifyCIMUser(const String& userName);
205
206 /**
|
207 kumpf 1.11 Verify user's password matches specified password
|
208 mike 1.2
|
209 kumpf 1.11 @param userName Name of the user to be verified
210 @param password password to be verified
211 @return true if the user's password matches existing password, else
212 false
|
213 mike 1.2
|
214 kumpf 1.11 @exception FileNotReadable if unable to read password file
215 @exception InvalidUser if the specified user does not exist
|
216 mike 1.2 */
217 Boolean verifyCIMUserPassword(
|
218 kumpf 1.11 const String& userName,
219 const String& password);
|
220 mike 1.2 };
221
222 PEGASUS_NAMESPACE_END
223
224 #endif /* Pegasus_UserFileHandler_h */
225
|