1 yi.zhou 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 yi.zhou 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/Constants.h>
36 #include <Pegasus/Common/Logger.h>
37 #include <Pegasus/Common/Formatter.h>
38 #include <Pegasus/Common/CIMPropertyList.h>
39 #include <Pegasus/Common/InternalException.h>
|
40 yi.zhou 1.2
41 #ifndef PEGASUS_OS_TYPE_WINDOWS
42 # include <unistd.h>
43 #endif
44
|
45 yi.zhou 1.1 #include <stdlib.h>
46
47 #ifndef PEGASUS_DISABLE_AUDIT_LOGGER
48
49 #include <Pegasus/Common/AuditLogger.h>
50
|
51 yi.zhou 1.3 extern char ** environ;
52
|
53 yi.zhou 1.1 PEGASUS_USING_STD;
54
55 PEGASUS_NAMESPACE_BEGIN
56
57 static const String providerModuleStatus [] = {"Unknown", "Other", "OK", "Degraded",
58 "Stressed", "Predictive Failure", "Error", "Non-Recoverable Error",
59 "Starting", "Stopping", "Stopped", "In Service", "No Contact",
60 "Lost Communication"};
61
62 Boolean AuditLogger::_auditLogFlag = false;
63
64 AuditLogger::PEGASUS_AUDITLOGINITIALIZE_CALLBACK_T AuditLogger::_auditLogInitializeCallback;
65
66 AuditLogger::PEGASUS_AUDITLOG_CALLBACK_T AuditLogger::_writeAuditMessageToFile =
67 AuditLogger::_writeAuditMessage;
68
69 void AuditLogger::logCurrentConfig(
70 const Array<String> & propertyNames,
71 const Array<String> & propertyValues)
72 {
73 String properties;
74 yi.zhou 1.1
75 for (Uint32 i = 0; i < propertyNames.size(); i++)
76 {
77 properties.append(propertyNames[i]);
78 properties.append("=");
79 properties.append(propertyValues[i]);
80 properties.append("\n");
81 }
82
83 MessageLoaderParms msgParms("Common.AuditLogger.CURRENT_CONFIG",
84 "The current configuration properties are:\n$0", properties);
85
|
86 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
87 SUBTYPE_CURRENT_CONFIGURATION,
88 EVENT_START_UP, Logger::INFORMATION, msgParms);
|
89 yi.zhou 1.1
90 }
91
92 void AuditLogger::logCurrentRegProvider(
93 const Array < CIMInstance > & instances)
94 {
95 String moduleName, registeredModules;
96 Array<Uint16> moduleStatus;
97 String statusValue;
98 Uint32 pos;
99
100 // get all the registered provider module names and status
101 for (Uint32 i = 0; i <instances.size(); i++)
102 {
103 instances[i].getProperty(instances[i].findProperty(
104 _PROPERTY_PROVIDERMODULE_NAME)).getValue().get(moduleName);
105
106 registeredModules.append(moduleName);
107 registeredModules.append("=");
108
109 pos = instances[i].findProperty(_PROPERTY_OPERATIONALSTATUS);
110 yi.zhou 1.1
111 if (pos == PEG_NOT_FOUND)
112 {
113 moduleStatus.append(0);
114 }
115 else
116 {
117 CIMValue theValue = instances[i].getProperty(pos).getValue();
118
119 if (theValue.isNull())
120 {
121 moduleStatus.append(0);
122 }
123 else
124 {
125 theValue.get(moduleStatus);
126 }
127 }
128
129 statusValue = _getModuleStatusValue(moduleStatus);
130
131 yi.zhou 1.1 registeredModules.append(statusValue);
132 registeredModules.append("\n");
133 }
134
135 MessageLoaderParms msgParms(
136 "Common.AuditLogger.CURRENT_PROVIDER_REGISTRATION",
137 "The current registered provider modules are:\n$0", registeredModules);
138
|
139 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
140 SUBTYPE_CURRENT_PROVIDER_REGISTRATION,
141 EVENT_START_UP, Logger::INFORMATION, msgParms);
|
142 yi.zhou 1.1 }
143
144 void AuditLogger::logCurrentEnvironmentVar()
145 {
146
147 String envList;
148 char ** envp = environ;
149
150 Uint32 i = 0;
151
152 while (envp[i])
153 {
154 envList.append(envp[i]);
155 envList.append("\n");
156
157 i++;
158 }
159
160 MessageLoaderParms msgParms("Common.AuditLogger.CURRENT_ENV",
161 "The current environment variables are:\n$0", envList);
162
|
163 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
164 SUBTYPE_CURRENT_ENVIRONMENT_VARIABLES,
165 EVENT_START_UP, Logger::INFORMATION, msgParms);
|
166 yi.zhou 1.1 }
167
168 void AuditLogger::logSetConfigProperty(
169 const String & userName,
170 const String & propertyName,
171 const String & prePropertyValue,
172 const String & newPropertyValue,
173 Boolean isPlanned)
174 {
175 if (isPlanned)
176 {
177 MessageLoaderParms msgParms(
178 "Common.AuditLogger.SET_PLANNED_CONFIG_PROPERTY",
179 "The planned value of property \"$0\" is modified from value \"$1\"" " to value \"$2\" by user \"$3\".\n",
180 propertyName, prePropertyValue, newPropertyValue, userName);
181
|
182 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
183 SUBTYPE_CONFIGURATION_CHANGE,
184 EVENT_UPDATE, Logger::INFORMATION, msgParms);
|
185 yi.zhou 1.1 }
186 else
187 {
188 MessageLoaderParms msgParms(
189 "Common.AuditLogger.SET_CURRENT_CONFIG_PROPERTY",
190 "The current value of property \"$0\" is modified from value "
191 "\"$1\" to value \"$2\" by user \"$3\".\n",
192 propertyName, prePropertyValue, newPropertyValue, userName);
193
|
194 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
195 SUBTYPE_CONFIGURATION_CHANGE,
196 EVENT_UPDATE, Logger::INFORMATION, msgParms);
|
197 yi.zhou 1.1 }
198 }
199
200 void AuditLogger::setInitializeCallback(
201 PEGASUS_AUDITLOGINITIALIZE_CALLBACK_T auditLogInitializeCallback)
202 {
203 _auditLogInitializeCallback = auditLogInitializeCallback;
204 }
205
206 void AuditLogger::setEnabled(Boolean enabled)
207 {
208 if (enabled)
209 {
210 if (!_auditLogFlag)
211 {
212 _auditLogInitializeCallback();
213 }
214 }
215 else
216 {
217 if (_auditLogFlag)
218 yi.zhou 1.1 {
219 MessageLoaderParms msgParms(
220 "Common.AuditLogger.DISABLE_AUDIT_LOG",
221 "Audit logging is disabled.\n");
222
|
223 yi.zhou 1.4 _writeAuditMessageToFile(TYPE_CONFIGURATION,
224 SUBTYPE_CONFIGURATION_CHANGE,
225 EVENT_UPDATE, Logger::INFORMATION, msgParms);
|
226 yi.zhou 1.1 }
227 }
228
229 _auditLogFlag = enabled;
230 }
231
232 void AuditLogger::writeAuditLogToFileCallback(
233 PEGASUS_AUDITLOG_CALLBACK_T writeAuditLogToFileCallback)
234 {
235 _writeAuditMessageToFile = writeAuditLogToFileCallback;
236 }
237
238 void AuditLogger::_writeAuditMessage(
239 AuditType auditType,
240 AuditSubType auditSubType,
241 AuditEvent auditEvent,
242 Uint32 logLevel,
243 MessageLoaderParms & msgParms)
244 {
245 String localizedMsg = MessageLoader::getMessage(msgParms);
246
247 yi.zhou 1.1 String identifier = "CIM Server Audit";
248
249 Logger::put(Logger::AUDIT_LOG, identifier, logLevel, localizedMsg);
250 }
251
252 String AuditLogger::_getModuleStatusValue(
253 const Array<Uint16> moduleStatus)
254 {
255 String moduleStatusValue, statusValue;
256 Uint32 moduleStatusSize = moduleStatus.size();
257
258 for (Uint32 j=0; j < moduleStatusSize; j++)
259 {
260 statusValue = providerModuleStatus[moduleStatus[j]];
261 moduleStatusValue.append(statusValue);
262
263 if (j < moduleStatusSize - 1)
264 {
265 moduleStatusValue.append(",");
266 }
267 }
268 yi.zhou 1.1
269 return (moduleStatusValue);
270 }
271
272 PEGASUS_NAMESPACE_END
273
274 #endif
|