(file) Return to Audit_zOS_SMF.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 martin 1.4 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.5 //
  3 martin 1.4 // 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.5 //
 10 martin 1.4 // 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.5 //
 17 martin 1.4 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.5 //
 20 martin 1.4 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.5 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.4 // 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.5 //
 28 martin 1.4 //////////////////////////////////////////////////////////////////////////
 29 thilo.boehm 1.1 //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 
 32                 #include <Pegasus/Common/Config.h>
 33                 #include <Pegasus/Common/Constants.h>
 34                 #include <Pegasus/Common/PegasusVersion.h>
 35                 #include <Pegasus/Common/Threads.h>
 36                 #include <Pegasus/Common/AuditLogger.h>
 37                 #include <Pegasus/Common/Tracer.h>
 38                 #include <Pegasus/Common/Audit_zOS_SMF.h>
 39                 
 40                 #include <sys/utsname.h>
 41                 
 42                 PEGASUS_USING_STD;
 43                 
 44                 PEGASUS_NAMESPACE_BEGIN
 45                 
 46                 static const char* CFZ_EBCDIC = "\xC3\xC6\xE9\x40";  // "CFZ " in EBCDIC
 47                 
 48                 
 49                 // Mutex Audit_zOS_SMF::_protectProlog;
 50 thilo.boehm 1.1 
 51                 Audit_zOS_SMF::Audit_zOS_SMF()
 52                 {
 53                     if (_recordProlog == NULL)
 54                     {
 55                         AutoMutex autoMut(_protectProlog);
 56                         if (_recordProlog == NULL)
 57                         {
 58 kumpf       1.6             _recordProlog = (_smf86_record_prolog*)calloc(1,
 59 thilo.boehm 1.1                 sizeof(_smf86_record_prolog));
 60                 
 61                             _preInitRecordHeaderSection(&(_recordProlog->header));
 62                             _preInitRecordProductSection(&(_recordProlog->product));
 63                 
 64                         }
 65                     }
 66                 
 67                 }
 68                 
 69                 Audit_zOS_SMF::~Audit_zOS_SMF()
 70                 {
 71                     if (_recordProlog != NULL)
 72                     {
 73                         AutoMutex huddel(_protectProlog);
 74                         free(_recordProlog);
 75                         _recordProlog = NULL;
 76                     }
 77                 }
 78                 
 79                 void Audit_zOS_SMF::initMyProlog( _smf86_record_prolog * myRecProlog,
 80 thilo.boehm 1.1                                 _smf_record_suptype subtype,
 81                                                 int subTypeSize)
 82                 {
 83                 
 84                     // copy the common prolog to the current record
 85                     memcpy(myRecProlog,_recordProlog, sizeof(_smf86_record_prolog));
 86                 
 87                     // set header subtye specific values.
 88                 
 89                     // Set total record length
 90                     myRecProlog->header.SMF86LEN=(sizeof(_smf86_record_prolog) + subTypeSize );
 91 kumpf       1.6     // We do no segmentaion in general
 92 thilo.boehm 1.1     myRecProlog->header.SMF86SEG=0;
 93                     // Set subtype
 94 kumpf       1.6     myRecProlog->header.SMF86STY=subtype;
 95 thilo.boehm 1.1     // Set size of subtype section
 96                     myRecProlog->header.SMF86STL=subTypeSize;
 97                 
 98                     // Set thread ID
 99 kumpf       1.6     setEBCDICRecordField( myRecProlog->product.SMF86THID,
100 thilo.boehm 1.1                           Threads::id().buffer,
101                                           sizeof(myRecProlog->product.SMF86THID),true);
102                 
103                     return;
104                 }
105                 
106                 Boolean Audit_zOS_SMF::isRecording(_smf_record_suptype subtype)
107                 {
108                     if (__smf_record(86,subtype,0,NULL) < 0)
109                     {
110                         PEG_TRACE((TRC_SERVER,Tracer::LEVEL4,
111                                    "SMF recording not enabled: \'%s\' "
112                                        "(errno(%d) reason code(0x%08X))",
113                                    strerror(errno),errno,__errno2()));
114                         return false;
115                     }
116                 
117                     return true;
118                 }
119                 
120                 void Audit_zOS_SMF::writeRecord(int subtype, char* record )
121 thilo.boehm 1.1 {
122 kumpf       1.6     // the size of the whole record is stored as short in the first bytes
123 thilo.boehm 1.1     // of the record.
124                     if (__smf_record(86,subtype,((_smf86_header *)record)->SMF86LEN,record) < 0)
125                     {
126 marek       1.2         PEG_TRACE((TRC_SERVER,Tracer::LEVEL2,
127                                    "Cannot write SMF records: \'%s\' "
128 thilo.boehm 1.1                        "(errno(%d) reason code(0x%08X))",
129                                    strerror(errno),errno,__errno2()));
130                     }
131 kumpf       1.6 
132 thilo.boehm 1.1     return;
133                 }
134                 
135                 
136                 void Audit_zOS_SMF::setEBCDICRecordField(
137 kumpf       1.6     unsigned char * field,
138                     const char * value,
139 thilo.boehm 1.1     int size, bool nullTerminated )
140                 {
141                     int length = strlen(value);
142                 
143                     // if the value size is larger then the filed size
144                     // cut the value to the size fitting in the field.
145                     if (length > size)
146                     {
147                         length = size;
148                     }
149                 
150                 
151                     memcpy((char *)field,value,length);
152                 
153                     if (nullTerminated)
154                     {
155                         field[length] = 0x00;
156                         length++;
157                     }
158                 
159                     while (length < size)
160 thilo.boehm 1.1     {
161                         field[length] = ' ';
162                         length++;
163                     }
164                 
165                     // convert the ascii field to ebcdic
166                     __a2e_l((char *)field,length);
167                 
168                 
169                 }
170                 
171                 
172                 void Audit_zOS_SMF::_preInitRecordHeaderSection( _smf86_header* recordHeader )
173                 {
174 kumpf       1.6 
175 thilo.boehm 1.1     recordHeader->SMF86FLG=0xFF;         // Set bit mask to 11111111;
176                     recordHeader->SMF86RTY=86;           // Set SMF reckord type
177                     recordHeader->SMF86TRN=2;            // Both triplets are used
178                                                          // set system identifyter
179                     memcpy(recordHeader->SMF86SSI,CFZ_EBCDIC,
180 r.kieninger 1.3            strlen(CFZ_EBCDIC));
181 thilo.boehm 1.1 
182                                                          // start of product section
183                     recordHeader->SMF86PRO=sizeof(_smf86_header);
184                                                          // size of product section
185                     recordHeader->SMF86PRL=sizeof(_smf86_product);
186                     recordHeader->SMF86PRN=1;            // one product section
187                                                          // start of subtype section
188                     recordHeader->SMF86STO=sizeof(_smf86_header)+
189                         sizeof(_smf86_product);
190                     recordHeader->SMF86STN=1;            // one subtype section
191                 }
192                 
193 kumpf       1.6 void Audit_zOS_SMF::_preInitRecordProductSection (
194 thilo.boehm 1.1     _smf86_product* recordProductSec )
195                 {
196 kumpf       1.6 
197 thilo.boehm 1.1     struct utsname uts;
198                     char zOS_VRM[sizeof(uts.version) +
199                                  sizeof(uts.release) + 2];
200                 
201                     // set to recrod version 1
202 kumpf       1.6     recordProductSec->SMF86PRRVN = 1;
203 thilo.boehm 1.1 
204                     // set system identifyter
205                     memcpy(recordProductSec->SMF86SSI,CFZ_EBCDIC,
206 r.kieninger 1.3            strlen(CFZ_EBCDIC));
207 thilo.boehm 1.1 
208                     // set pegasus VRM
209 kumpf       1.6     setEBCDICRecordField( recordProductSec->SMF86VRM,
210 thilo.boehm 1.1                         PEGASUS_PRODUCT_VERSION,
211                                         sizeof(recordProductSec->SMF86VRM),false);
212                      if (__osname(&uts) > -1 )
213                      {
214                 
215                          zOS_VRM[0] = 0;
216                          strcat(zOS_VRM,uts.version);
217                          strcat(zOS_VRM,".");
218                          strcat(zOS_VRM,uts.release);
219                 
220                          // set OS VRM
221 kumpf       1.6          setEBCDICRecordField( recordProductSec->SMF86OSL,
222 thilo.boehm 1.1                              zOS_VRM,
223                                              sizeof(recordProductSec->SMF86OSL),false);
224                 
225                          // set system name
226 kumpf       1.6          setEBCDICRecordField( recordProductSec->SMF86SYN,
227 thilo.boehm 1.1                              uts.nodename,
228                                              sizeof(recordProductSec->SMF86SYN),false);
229                      } else
230                      {
231 marek       1.2          PEG_TRACE((TRC_SERVER,Tracer::LEVEL1,
232                              "Cannot get OS version and system name: \'%s\' (errno(%d) "
233 thilo.boehm 1.1              "reason code(%08X))",
234                               strerror(errno),errno,__errno2()));
235                      }
236                 
237                                                  // set sysplex name
238                      _setSysplexName( recordProductSec->SMF86SYP);
239                 
240                      recordProductSec->SMF86OPI = System::getPID();
241                 
242                 }
243                 
244                 
245                 void Audit_zOS_SMF::_setSysplexName(unsigned char * field)
246                 {
247                     // Get pointer to the CVT control block
248                     int * p = (int *)16;
249                     int * cvt_ptr = (int *) *(p);
250                     // Get pointer to the eCVT control block
251                     int * ecvt_ptr = (int *) *(cvt_ptr+35); // 4*35 = 140 Byte
252                     // Get pointer to the sysplex name
253                     char * ECVTSPLX = (char *)(ecvt_ptr+2); // 4*2 = 8 Byte
254 thilo.boehm 1.1 
255                     memcpy((char*)field, ECVTSPLX, 8);
256                 }
257                 
258                 void Audit_zOS_SMF::printRecord (int subtype, char* record )
259                 {
260                     char printLine[3][80];
261                     int p;
262                     int len;
263                     char item;
264                     int total = ((_smf86_header *)record)->SMF86LEN;
265                 
266                     printf("\n Char/HEX output(%08X)\n\n",System::getPID());
267                 
268                     for (int i = 0; i <= total;i=i+1)
269                     {
270                         p = i%80;
271                 
272                         if (p == 0 && i > 0 ||
273                             i == total )
274                         {
275 thilo.boehm 1.1             for (int y = 0; y < 3; y=y+1)
276 kumpf       1.6             {
277 thilo.boehm 1.1                 if (p == 0)
278                                 {
279                                     len = 80;
280                                 } else
281                                 {
282                                     len = p;
283                                 }
284                 
285                                 for (int x = 0; x < len; x=x+1)
286                                 {
287                                     if (y == 0)
288                                     {
289                                         printf("%c",printLine[y][x]);
290 kumpf       1.6                     }
291 thilo.boehm 1.1                     else
292                                     {
293                                         printf("%1X",printLine[y][x]);
294 kumpf       1.6                     }
295 thilo.boehm 1.1                 }
296                                 printf("\n");
297                             }
298                             printf("\n");
299                         }
300                 
301                         item = record[i];
302                         __e2a_l(&item,1);
303                 
304                         if (item < 32 || item > 126)
305                         {
306                             printLine[0][p] = '.';
307                         } else
308                         {
309                             printLine[0][p] = item;
310                         }
311                 
312                         printLine[1][p] = record[i]/16;
313                         printLine[2][p] = record[i]%16;
314                 
315                 
316 thilo.boehm 1.1     }
317                 }
318                 
319                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2