2
/*___INFO__MARK_BEGIN__*/
3
/*************************************************************************
5
* The Contents of this file are made available subject to the terms of
6
* the Sun Industry Standards Source License Version 1.2
8
* Sun Microsystems Inc., March, 2001
11
* Sun Industry Standards Source License Version 1.2
12
* =================================================
13
* The contents of this file are subject to the Sun Industry Standards
14
* Source License Version 1.2 (the "License"); You may not use this file
15
* except in compliance with the License. You may obtain a copy of the
16
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
18
* Software provided under this License is provided on an "AS IS" basis,
19
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
20
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
21
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
22
* See the License for the specific provisions governing your rights and
23
* obligations concerning the Software.
25
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
27
* Copyright: 2001 by Sun Microsystems, Inc.
29
* All Rights Reserved.
31
************************************************************************/
32
/*___INFO__MARK_END__*/
42
#include "cl_commlib.h"
43
#include "cl_log_list.h"
44
#include "cl_endpoint_list.h"
45
#include "uti/sge_profiling.h"
48
void sighandler_server(int sig);
49
static int pipe_signal = 0;
50
static int hup_signal = 0;
51
static int do_shutdown = 0;
52
static int received_qping = 0;
54
void sighandler_server(
67
/* shutdown all sockets */
68
cl_com_ignore_timeouts(CL_TRUE);
73
const char* my_application_tag_name(unsigned long tag) {
77
return "DEFAULT_APPLICATION_TAG";
80
unsigned long my_application_status(char** info_message) {
81
if ( info_message != NULL ) {
82
(*info_message) = strdup("not specified (state 1)");
87
if (received_qping > 10) {
90
return (unsigned long)1;
93
#ifdef __CL_FUNCTION__
94
#undef __CL_FUNCTION__
96
#define __CL_FUNCTION__ "my_ssl_verify_func()"
97
static cl_bool_t my_ssl_verify_func(cl_ssl_verify_mode_t mode, cl_bool_t service_mode, const char* value) {
98
char* user_name = NULL;
99
struct passwd *paswd = NULL;
101
paswd = getpwuid(getuid());
103
user_name = paswd->pw_name;
105
if (user_name == NULL) {
106
user_name = "unexpected user name";
108
if (service_mode == CL_TRUE) {
109
CL_LOG(CL_LOG_WARNING,"running in service mode");
111
case CL_SSL_PEER_NAME: {
112
CL_LOG(CL_LOG_WARNING,"CL_SSL_PEER_NAME");
113
if (strcmp(value,"SGE admin user") != 0) {
114
CL_LOG(CL_LOG_WARNING,"CL_SSL_PEER_NAME is not \"SGE admin user\"");
119
case CL_SSL_USER_NAME: {
120
CL_LOG(CL_LOG_WARNING,"CL_SSL_USER_NAME");
121
if (strcmp(value,user_name) != 0) {
122
CL_LOG_STR(CL_LOG_WARNING,"CL_SSL_USER_NAME is not", user_name);
129
CL_LOG(CL_LOG_WARNING,"running in client mode");
131
case CL_SSL_PEER_NAME: {
132
CL_LOG(CL_LOG_WARNING,"CL_SSL_PEER_NAME");
133
if (strcmp(value,"SGE admin user") != 0) {
134
CL_LOG(CL_LOG_WARNING,"CL_SSL_PEER_NAME is not \"SGE Daemon\"");
139
case CL_SSL_USER_NAME: {
140
CL_LOG(CL_LOG_WARNING,"CL_SSL_USER_NAME");
141
if (strcmp(value,user_name) != 0) {
142
CL_LOG_STR(CL_LOG_WARNING,"CL_SSL_USER_NAME is not", user_name);
153
#ifdef __CL_FUNCTION__
154
#undef __CL_FUNCTION__
156
#define __CL_FUNCTION__ "main()"
157
extern int main(int argc, char** argv)
160
cl_ssl_setup_t ssl_config;
161
static int runs = 100;
165
cl_com_handle_t* handle = NULL;
166
cl_com_message_t* message = NULL;
167
cl_com_endpoint_t* sender = NULL;
169
unsigned long max_connections;
171
cl_framework_t framework = CL_CT_TCP;
173
ssl_config.ssl_method = CL_SSL_v23; /* v23 method */
174
ssl_config.ssl_CA_cert_pem_file = getenv("SSL_CA_CERT_FILE"); /* CA certificate file */
175
ssl_config.ssl_CA_key_pem_file = NULL; /* private certificate file of CA (not used) */
176
ssl_config.ssl_cert_pem_file = getenv("SSL_CERT_FILE"); /* certificates file */
177
ssl_config.ssl_key_pem_file = getenv("SSL_KEY_FILE"); /* key file */
178
ssl_config.ssl_rand_file = getenv("SSL_RAND_FILE"); /* rand file (if RAND_status() not ok) */
179
ssl_config.ssl_crl_file = getenv("SSL_CRL_FILE"); /* revocation list file */
180
ssl_config.ssl_reconnect_file = NULL; /* file for reconnect data (not used) */
181
ssl_config.ssl_refresh_time = 0; /* key alive time for connections (not used) */
182
ssl_config.ssl_password = NULL; /* password for encrypted keyfiles (not used) */
183
ssl_config.ssl_verify_func = my_ssl_verify_func; /* function callback for peer user/name check */
185
if (getenv("CL_PORT")) {
186
handle_port = atoi(getenv("CL_PORT"));
190
printf("param1=debug_level [param2=framework(TCP/SSL)]\n");
197
framework = CL_CT_UNDEFINED;
198
if (strcmp(argv[2], "TCP") == 0) {
200
printf("using TCP framework\n");
202
if (strcmp(argv[2], "SSL") == 0) {
204
printf("using SSL framework\n");
206
if (ssl_config.ssl_CA_cert_pem_file == NULL ||
207
ssl_config.ssl_cert_pem_file == NULL ||
208
ssl_config.ssl_key_pem_file == NULL ||
209
ssl_config.ssl_rand_file == NULL) {
210
printf("please set the following environment variables:\n");
211
printf("SSL_CA_CERT_FILE = CA certificate file\n");
212
printf("SSL_CERT_FILE = certificates file\n");
213
printf("SSL_KEY_FILE = key file\n");
214
printf("(optional) SSL_RAND_FILE = rand file (if RAND_status() not ok)\n");
217
if (framework == CL_CT_UNDEFINED) {
218
printf("unexpected framework type\n");
223
/* setup signalhandling */
224
memset(&sa, 0, sizeof(sa));
225
sa.sa_handler = sighandler_server; /* one handler for all signals */
226
sigemptyset(&sa.sa_mask);
227
sigaction(SIGINT, &sa, NULL);
228
sigaction(SIGTERM, &sa, NULL);
229
sigaction(SIGHUP, &sa, NULL);
230
sigaction(SIGPIPE, &sa, NULL);
233
printf("commlib setup ...\n");
234
/* this is for compiler warning on irix65 */
242
switch(atoi(argv[1])) {
244
log_level=CL_LOG_OFF;
247
log_level=CL_LOG_ERROR;
250
log_level=CL_LOG_WARNING;
253
log_level=CL_LOG_INFO;
256
log_level=CL_LOG_DEBUG;
259
log_level=CL_LOG_OFF;
262
cl_com_setup_commlib(CL_RW_THREAD, log_level, NULL);
265
cl_com_set_parameter_list_value("parameter1","value1");
266
cl_com_set_parameter_list_value("parameter2","value2");
267
cl_com_set_parameter_list_value("parameter3","value3");
268
cl_com_set_parameter_list_value("parameter4","value4");
270
cl_com_set_alias_file("./alias_file");
272
cl_com_set_status_func(my_application_status);
274
cl_com_set_tag_name_func(my_application_tag_name);
276
cl_com_specify_ssl_configuration(&ssl_config);
278
handle=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_TRUE, handle_port, CL_TCP_DEFAULT, "server", 1, 1, 0 );
279
if (handle == NULL) {
280
printf("could not get handle\n");
281
cl_com_cleanup_commlib();
286
cl_com_get_service_port(handle,&i),
289
printf("server running on host \"%s\", port %d, component name is \"%s\", id is %ld\n",
290
handle->local->comp_host,
292
handle->local->comp_name,
293
handle->local->comp_id);
295
cl_com_add_allowed_host(handle, handle->local->comp_host);
297
cl_com_get_max_connections(handle,&max_connections);
298
printf("max open connections is set to %lu\n", max_connections);
299
cl_com_set_max_connection_close_mode(handle,CL_ON_MAX_COUNT_CLOSE_AUTOCLOSE_CLIENTS );
302
cl_com_append_known_endpoint_from_name(handle->local->comp_host, "server", 1, 5000, CL_CM_AC_ENABLED, CL_FALSE );
304
if (getenv("CL_RUNS")) {
305
runs = atoi(getenv("CL_RUNS"));
307
while(do_shutdown != 1) {
310
CL_LOG(CL_LOG_INFO,"main()");
311
cl_commlib_trigger(handle, 1);
313
if (getenv("CL_RUNS")) {
314
printf("runs: %d\n", runs);
323
cl_raw_list_t* tmp_endpoint_list = NULL;
324
cl_endpoint_list_elem_t* elem = NULL;
326
cl_commlib_search_endpoint(handle, NULL, NULL, 1, CL_TRUE, &tmp_endpoint_list);
327
elem = cl_endpoint_list_get_first_elem(tmp_endpoint_list);
328
printf("\nconnected endpoints with id=1:\n");
329
printf("==============================\n");
332
printf("%s/%s/%d\n", elem->endpoint->comp_host, elem->endpoint->comp_name, elem->endpoint->comp_id);
333
elem = cl_endpoint_list_get_next_elem(tmp_endpoint_list, elem);
335
cl_endpoint_list_cleanup(&tmp_endpoint_list);
337
cl_commlib_search_endpoint(handle, NULL, NULL, 1, CL_FALSE, &tmp_endpoint_list);
338
elem = cl_endpoint_list_get_first_elem(tmp_endpoint_list);
339
printf("\nconnected and known endpoints with id=1:\n");
340
printf("=========================================\n");
343
printf("%s/%s/%d\n", elem->endpoint->comp_host, elem->endpoint->comp_name, elem->endpoint->comp_id);
344
elem = cl_endpoint_list_get_next_elem(tmp_endpoint_list, elem);
346
cl_endpoint_list_cleanup(&tmp_endpoint_list);
348
cl_commlib_search_endpoint(handle, NULL, "client", 0, CL_FALSE, &tmp_endpoint_list);
349
elem = cl_endpoint_list_get_first_elem(tmp_endpoint_list);
350
printf("\nconnected and known endpoints with comp_name=client:\n");
351
printf("=====================================================\n");
354
printf("%s/%s/%d\n", elem->endpoint->comp_host, elem->endpoint->comp_name, elem->endpoint->comp_id);
355
elem = cl_endpoint_list_get_next_elem(tmp_endpoint_list, elem);
357
cl_endpoint_list_cleanup(&tmp_endpoint_list);
362
/* TODO: check behaviour for unknown host and for a host which is down */
363
cl_commlib_send_message(handle, "down_host", "nocomp", 1, CL_MIH_MAT_ACK, (cl_byte_t*)"blub", 5, NULL, 1, 1 ); /* check wait for ack / ack_types TODO*/
366
ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
367
CL_LOG_STR(CL_LOG_INFO,"cl_commlib_receive_message() returned",cl_get_error_text(ret_val));
369
if (message != NULL) {
370
CL_LOG_STR(CL_LOG_INFO,"received message from",sender->comp_host);
372
/* printf("received message from \"%s/%s/%ld\"\n", sender->comp_host, sender->comp_name, sender->comp_id); */
376
if (strstr((char*)message->message,"exit") != NULL) {
377
printf("received \"exit\" message from host %s, component %s, id %ld\n",
378
sender->comp_host,sender->comp_name,sender->comp_id );
379
cl_commlib_close_connection(handle, sender->comp_host,sender->comp_name,sender->comp_id, CL_FALSE );
382
ret_val = cl_commlib_send_message(handle,
385
sender->comp_id, CL_MIH_MAT_NAK,
387
message->message_length,
388
NULL, message->message_id,0,
390
if (ret_val != CL_RETVAL_OK) {
391
CL_LOG_INT(CL_LOG_ERROR,"sent message response for message id", (int)message->message_id);
392
CL_LOG_STR(CL_LOG_ERROR,"cl_commlib_send_message() returned:",cl_get_error_text(ret_val));
394
CL_LOG_INT(CL_LOG_INFO,"sent message response for message id", (int)message->message_id);
396
cl_com_application_debug(handle, "message sent (1)");
397
cl_com_application_debug(handle, "message sent (2)");
400
cl_com_free_message(&message);
401
cl_com_free_endpoint(&sender);
409
printf("shutting down server ...\n");
410
handle = cl_com_get_handle( "server", 1 );
411
if (handle == NULL) {
412
printf("could not find handle\n");
415
printf("found handle\n");
418
while ( cl_commlib_shutdown_handle(handle, CL_TRUE) == CL_RETVAL_MESSAGE_IN_BUFFER) {
420
cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
422
if (message != NULL) {
423
printf("ignoring message from \"%s\"\n", sender->comp_host);
424
cl_com_free_message(&message);
425
cl_com_free_endpoint(&sender);
430
printf("commlib cleanup ...\n");
431
cl_com_cleanup_commlib();
435
printf("main done\n");