1 karl 1.8 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
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 karl 1.8 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 1.1 //
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 // 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 h.sterling 1.1 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <unistd.h>
|
38 chuck 1.3 #include <sys/wait.h>
|
39 h.sterling 1.1 #include <Pegasus/Common/Config.h>
40 #include <Pegasus/Common/String.h>
41 #include <Pegasus/Common/Logger.h>
|
42 chuck 1.3 #include <Pegasus/Config/ConfigManager.h>
|
43 h.sterling 1.1 #include "OS400ConvertChar.h"
|
44 chuck 1.3 #include "SSLWrapperOS400.h"
45 #include "OS400SystemState.h"
|
46 lucier 1.4 #include "CIMRepositoryUpdate400.h" // upgrade utility
|
47 h.sterling 1.1 #include <Pegasus/Common/MessageLoader.h> //l10n
48 #include <except.h>
49
50 #include <stdio.h>
51 #include "qycmutiltyUtility.H"
52 #include "qycmjobjobJob.H"
53 #include "qycmmsgclsMessage.H"
54 #include "licall.h" // EPTCALL macros.
55
56 // Needed for QWTCHGJB API
57 #include <qwtchgjb.cleinc>
58 #include "qushdler.H"
59
60 //Needed for SQL APIs
61 #include "sqlcli.h"
62
63 // Structure need for the CHGJOB(QWTCHGJB) API
64 typedef struct jobChangeInfo
65 {
66 Qus_Job_Change_Information_t fieldNum;
67 Qus_JOBC0100_t format;
68 h.sterling 1.1 char data[31];
69 } jobChangeInfo_t;
70
71 // Errorcode for system API calls
72 Qus_EC_t errorCode;
73
74 PEGASUS_USING_PEGASUS;
75 PEGASUS_USING_STD;
76
77
78 //constructor
79 ServerProcess::ServerProcess() {}
80
81 //destructor
82 ServerProcess::~ServerProcess() {}
83
84 // no-ops
85 void ServerProcess::notify_parent(int id) {}
86 void ServerProcess::cimserver_set_process(void* p) {}
87 int ServerProcess::cimserver_wait(void) { return 1; }
88 String ServerProcess::getHome(void) { return String::EMPTY; }
89 h.sterling 1.1
90 ///////////////////////////////////////////////////////////////////////
91 // cimserver_fork()
92 //
93 // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
94 // already checked that the CIMOM server is not already running prior
95 // to calling the CIMOM server (QYCMCIMOM) and telling it to start itself.
96 // Therefore, no check is made in this method to ensure the CIMOM server
97 // is not already running.
98 //
99 // Note: This code was written because fork( ) is not supported on OS/400.
100 ///////////////////////////////////////////////////////////////////////
101 int ServerProcess::cimserver_fork(void)
102 {
|
103 lucier 1.4 // First migrate the server configuration settings into the planned file.
104 CIMRepositoryUpdate400 obj;
105 obj.preserveConfigSettings();
106
|
107 lucier 1.5 // TODO: This is here for now until we can move it into initialize. Right now it doesn't run because qycmsetupr won't work in a multi-threaded environment. See issue #AD2
108 obj.doIt();
109
|
110 h.sterling 1.1 #pragma convert(37)
111 char rc5[3] = "05"; // rc5 means the CIMOM Server failed to start
112 char cppServ[10] = "QYCMCIMOM";
113 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
114
115 // Submit the server job (QYCMCIMOM). The job is submitted with the
116 // daemon=false parameter to avoid an infinite loop of jobs being
117 // submitted by this code!
118 if (YCMJOB_SUBMIT_FAILED == cppJob.submit(YCMJOB_SRVR_PGM,
119 YCMJOB_QSYS_LIB,
120 "daemon=false",
121 YCMJOB_JOBD,
122 YCMJOB_QSYS_LIB,
123 YCMJOB_CCSID_37,
124 YCMJOB_THREAD_YES))
125 { // QYCMCIMOM Server Failed on Submit Job
126 #pragma convert(0)
127
128 //l10n
129 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
130 //"cimserver_os400::cimserver_fork() - SBMJOB failed to start the QYCMCIMOM server program!!");
131 h.sterling 1.1 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
132 "src.Server.cimserver_os400.FAILED_TO_START_SERVER",
133 "$0 failed to start the $1 server program!!",
134 "cimserver_os400::cimserver_fork() - SBMJOB",
135 "QYCMCIMOM");
136
137
138 char chData[sizeof(rc5)+sizeof(cppServ)];
139 strcpy((char *)&chData,rc5);
140 strcat(chData,cppServ);
141
142 #pragma convert(37)
143 ycmMessage message("CPDDF80",
144 chData,
145 strlen(chData),
146 "cimserver_os400::cimserver_fork()",
147 ycmCTLCIMID,
148 utf8);
149 message.joblogIt(UserError,ycmMessage::Diagnostic);
150 #pragma convert(0)
151
152 h.sterling 1.1 // save the job log
153 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
154
155
156 return(-1); // -1 indicates to QYCMCIMOM that the server failed to start
157 }
158
159 // The QYCMCIMOM job was submitted with daemon=false. This job can now exit.
160 // This is similiar to what the unix version of this code does - the parent exits
161 // after the fork( )
162 return(0);
163 }
164
165
166 ////////////////////////////////////////////////////
167 // CancelHandler
168 ////////////////////////////////////////////////////
169 void CancelHandler (_CNL_Hndlr_Parms_T *cancelParms)
170 { // make sure a job log gets saved too
171 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
172 }
173 h.sterling 1.1
174
175 ////////////////////////////////////////////////////
176 // iSeries-specific function to initialize the server.
177 // Does the following:
178 // -- Sets the server type to QIBM_CIMOM
179 // so that iNavigator can start/stop it.
180 // -- Swaps the job user to QSYS.
181 // -- Changes the authority of QYCMJOBD
|
182 lucier 1.5 // -- Calls the upgrade utility
|
183 h.sterling 1.1 ////////////////////////////////////////////////////
184 int ServerProcess::cimserver_initialize(void)
185 {
186 SQLHENV henv; // SQL environment variable
187 long attr; // SQL attribute to be set
188
189 // setup cancel handler to make sure job log gets saved if we exit abnormally
190 // TODO: this is currently commented out because it causes build errors -
191 // it compiles just fine though. Hopefully this problem will be fixed
192 // (it's a known problem) and we can uncomment this #pragma.
193 // #pragma cancel_handler (CancelHandler, NULL)
194 try {
195
196 #pragma convert(37)
197 //////////////////////////////////////////
198 // Change Job API call
199 // Change the server type to QICM_CIMOM
200 //////////////////////////////////////////
201 jobChangeInfo_t chg = {1,
202 46,
203 1911,
204 h.sterling 1.1 'C',
205 0X40,0X40,0X40,30,
206 "QIBM_CIMOM ",
207 };
208
209 // Initialize the error code structure to signal exceptions
210 errorCode.Bytes_Provided = 0;
211
212 // Call CHGJOB API with Server Type field
213 EPTCALL(QWTCHGJB, ("* ",
214 " ",
215 "JOBC0200",
216 &chg,
217 &errorCode), OFF, OFF);
218 #pragma convert(0)
219
220 ////////////////////////////////////////////////////
221 // Change authority to the qypsjobd job description
222 ////////////////////////////////////////////////////
223 system("QSYS/GRTOBJAUT OBJ(QSYS/QYCMJOBD) OBJTYPE(*JOBD) USER(*PUBLIC) AUT(*EXCLUDE)");
224
225 h.sterling 1.1 SQLAllocEnv(&henv); // Allocating SQL environment variable
226 attr = SQL_TRUE; // Set SQL attribute to true
227
228 // Set the SQL server mode to true.
229 // This will allow multiple connections to the same data source.
230 SQLSetEnvAttr(henv,SQL_ATTR_SERVER_MODE, &attr,0);
|
231 chuck 1.3
232 //--------------------------------------------------
233 // Create server SSL certificate and private key
234 // if they do not already exist.
235 //--------------------------------------------------
236
|
237 sushma.fernandes 1.10 // Check if SSL is enabled on the wbem-https port
|
238 chuck 1.3 ConfigManager * configManager = ConfigManager::getInstance();
|
239 kumpf 1.9 Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
240 configManager->getCurrentValue("enableHttpsConnection"));
|
241 sushma.fernandes 1.10 if (enableHttpsConnection)
|
242 chuck 1.3 {
243 // Initialize the OS400 OpenSSL wrapper.
244 // This checks if the OpenSSL LPO is installed.
245 // It also activates the OpenSSL *SRVPGM and gets exports.
246 SSL_OS400_Init();
247
248 // Create the certificate if needed
249 // Get the location of the certificate
250 String certPath;
251 certPath = ConfigManager::getHomedPath(
252 configManager->getCurrentValue("sslCertificateFilePath"));
253
254 // Get the location of the private key
255 String keyPath;
256 keyPath = ConfigManager::getHomedPath(
257 configManager->getCurrentValue("sslKeyFilePath"));
258
259 SSL_CreateCert_OS400(keyPath, certPath);
260 }
261 }
262 catch (Exception & e)
263 chuck 1.3 {
264 //l10n
265 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
266 e.getMessage());
267 return(-1);
268 }
|
269 h.sterling 1.1 catch (...)
270 {
271 //l10n
272 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
273 //"cimerver_os400::cimserver_os400_setup() - caught unknown exception\n");
274 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
275 "src.Server.cimserver_os400.CAUGHT_UNKNOWN_EXCEPTION",
276 "$0 caught unknown exception\n",
277 "cimerver_os400::cimserver_os400_setup() -");
278
279 return(-1);
280 }
|
281 lucier 1.4
|
282 lucier 1.5 // TODO: add this back in when we fix the problem with setupr not working in a multi-threaded environment.
|
283 lucier 1.4 // Call into the upgrade utility. This will perform any necessary upgrade step that need to be done. The upgrade program keys off of marker files which are created on install. This means that in most cases, nothing will be done unless the server is starting for the first time after an install.
|
284 lucier 1.5 // CIMRepositoryUpdate400 obj;
285 // obj.doIt();
|
286 h.sterling 1.1
287 // TODO: this is currently commented out because it causes build errors -
288 // it compiles just fine though. Hopefully this problem will be fixed
289 // (it's a known problem) and we can uncomment this #pragma.
290 // #pragma disable_handler
291
292 return(0);
293 }
294
295 ////////////////////////////////////////////////////
296 // Setup a fifo for process communication
297 ////////////////////////////////////////////////////
298 int init_fifo(const char * fifo_name){
299 int fifo = -1;
300 struct stat FIFO_STAT;
301
302 // Need to convert the fifo name to ebcdic because
303 // that is what stat and open want.
304 char tmp[256];
305 strcpy(tmp, fifo_name);
306 AtoE(tmp);
307 h.sterling 1.1
308 int stat_rc = stat( tmp, &FIFO_STAT );
309
310 // check if the FIFO already exists
311 if( S_ISFIFO( FIFO_STAT.st_mode ) ){
312 // prep FIFO, on this end we only want to write to it,
313 // set its I/O mode to not block on any reads
314 fifo = open(tmp, O_RDWR | O_NONBLOCK);
315 }
316 return fifo;
317 }
318
319
320 ////////////////////////////////////////////////////
321 // Sends return code back to caller before exiting...
322 ////////////////////////////////////////////////////
323 void ServerProcess::cimserver_exitRC(int rc){
324 int fifo = init_fifo(QYCMSSERV_FIFO);
325
326 if( fifo != -1 ){
327 char rc_tmp[3];
328 h.sterling 1.1 memset(rc_tmp, 0, 3);
329 sprintf(rc_tmp,"%d",rc);
330 AtoE(rc_tmp); // qycmctlcim wants ebcdic
331 write(fifo,rc_tmp,strlen(rc_tmp));
332 }
333
334 exit(rc);
335 }
336
337 ////////////////////////////////////////////////////
338 // Platform specific run
339 ////////////////////////////////////////////////////
|
340 kumpf 1.7 int ServerProcess::platform_run(
341 int argc,
342 char** argv,
343 Boolean shutdownOption,
344 Boolean debugOutputOption)
|
345 h.sterling 1.1 {
|
346 kumpf 1.7 return cimserver_run(argc, argv, shutdownOption, debugOutputOption);
|
347 h.sterling 1.1 }
348
|