| 1 | /* | |
| 2 | * Copyright 1999-2006 University of Chicago | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL | |
| 18 | ||
| 19 | #include "globus_common.h" | |
| 20 | #include "globus_i_wsrf_options.h" | |
| 21 | #include "globus_wsrf_core_tools.h" | |
| 22 | #include "gssapi.h" | |
| 23 | #include "globus_error_gssapi.h" | |
| 24 | #include "version.h" | |
| 25 | ||
| 26 | #ifndef GSS_IMPEXP_MECH_SPECIFIC | |
| 27 | #define GSS_IMPEXP_MECH_SPECIFIC 1 | |
| 28 | #endif | |
| 29 | #ifndef GSS_IMPEXP_OPAQUE_FORM | |
| 30 | #define GSS_IMPEXP_OPAQUE_FORM 0 | |
| 31 | #endif | |
| 32 | ||
| 33 | static | |
| 34 | globus_result_t | |
| 35 | globus_l_wsrf_options_set_anonymous( | |
| 36 | globus_options_handle_t opts_handle, | |
| 37 | char * cmd, | |
| 38 | char * param[], | |
| 39 | void * arg, | |
| 40 | int * out_params_used) | |
| 41 | 0 | { |
| 42 | globus_result_t result; | |
| 43 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 44 | ||
| 45 | 0 | result = globus_soap_message_attr_set( |
| 46 | options->attr, | |
| 47 | GLOBUS_SOAP_MESSAGE_AUTH_ANONYMOUS_KEY, | |
| 48 | NULL, | |
| 49 | NULL, | |
| 50 | (void *) 1); | |
| 51 | ||
| 52 | 0 | return result; |
| 53 | } | |
| 54 | /* globus_l_wsrf_options_set_anonymous() */ | |
| 55 | ||
| 56 | #if 0 | |
| 57 | static | |
| 58 | globus_result_t | |
| 59 | globus_l_wsrf_options_set_server_certificate( | |
| 60 | globus_options_handle_t opts_handle, | |
| 61 | char * cmd, | |
| 62 | char * param[], | |
| 63 | void * arg, | |
| 64 | int * out_params_used) | |
| 65 | { | |
| 66 | return GLOBUS_FAILURE; | |
| 67 | } | |
| 68 | /* globus_l_wsrf_options_set_server_certificate() */ | |
| 69 | #endif | |
| 70 | ||
| 71 | static | |
| 72 | globus_result_t | |
| 73 | globus_l_wsrf_options_set_debug( | |
| 74 | globus_options_handle_t opts_handle, | |
| 75 | char * cmd, | |
| 76 | char * param[], | |
| 77 | void * arg, | |
| 78 | int * out_params_used) | |
| 79 | 0 | { |
| 80 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 81 | ||
| 82 | 0 | options->debug = GLOBUS_TRUE; |
| 83 | #ifdef BUILD_DEBUG | |
| 84 | 0 | globus_i_GLOBUS_SOAP_MESSAGE_debug_handle.levels |= GLOBUS_SOAP_MESSAGE_DEBUG_MESSAGES; |
| 85 | #endif | |
| 86 | ||
| 87 | 0 | return GLOBUS_SUCCESS; |
| 88 | } | |
| 89 | /* globus_l_wsrf_options_set_debug() */ | |
| 90 | ||
| 91 | static | |
| 92 | globus_result_t | |
| 93 | globus_l_wsrf_options_set_epr( | |
| 94 | globus_options_handle_t opts_handle, | |
| 95 | char * cmd, | |
| 96 | char * param[], | |
| 97 | void * arg, | |
| 98 | int * out_params_used) | |
| 99 | 60 | { |
| 100 | 60 | globus_i_wsrf_options_handle_t * options = arg; |
| 101 | globus_result_t result; | |
| 102 | ||
| 103 | 60 | if (options->epr) |
| 104 | { | |
| 105 | 0 | wsa_EndpointReferenceType_destroy(options->epr); |
| 106 | } | |
| 107 | 60 | result = globus_wsrf_core_import_endpoint_reference( |
| 108 | param[0], | |
| 109 | &options->epr, | |
| 110 | NULL); | |
| 111 | ||
| 112 | 60 | return result; |
| 113 | } | |
| 114 | /* globus_l_wsrf_options_set_epr() */ | |
| 115 | ||
| 116 | #if 0 | |
| 117 | static | |
| 118 | globus_result_t | |
| 119 | globus_l_wsrf_options_set_descriptor( | |
| 120 | globus_options_handle_t opts_handle, | |
| 121 | char * cmd, | |
| 122 | char * param[], | |
| 123 | void * arg, | |
| 124 | int * out_params_used) | |
| 125 | { | |
| 126 | return GLOBUS_FAILURE; | |
| 127 | } | |
| 128 | /* globus_l_wsrf_options_set_descriptor() */ | |
| 129 | #endif | |
| 130 | ||
| 131 | #if 0 | |
| 132 | static | |
| 133 | globus_result_t | |
| 134 | globus_l_wsrf_options_set_delegation( | |
| 135 | globus_options_handle_t opts_handle, | |
| 136 | char * cmd, | |
| 137 | char * param[], | |
| 138 | void * arg, | |
| 139 | int * out_params_used) | |
| 140 | { | |
| 141 | return GLOBUS_FAILURE; | |
| 142 | } | |
| 143 | /* globus_l_wsrf_options_set_delegation() */ | |
| 144 | #endif | |
| 145 | ||
| 146 | static | |
| 147 | globus_result_t | |
| 148 | globus_l_wsrf_options_set_help( | |
| 149 | globus_options_handle_t opts_handle, | |
| 150 | char * cmd, | |
| 151 | char * param[], | |
| 152 | void * arg, | |
| 153 | int * out_params_used) | |
| 154 | 0 | { |
| 155 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 156 | const char * tmp; | |
| 157 | ||
| 158 | 0 | if (options->application_name) |
| 159 | { | |
| 160 | 0 | tmp = strrchr(options->application_name, '/'); |
| 161 | 0 | tmp = tmp ? tmp+1 : options->application_name; |
| 162 | } | |
| 163 | else | |
| 164 | { | |
| 165 | 0 | tmp = "globus_wsrf_core_tools"; |
| 166 | } | |
| 167 | 0 | if (options->usage) |
| 168 | { | |
| 169 | 0 | printf("Usage: %s %s\nOptions:\n", tmp, options->usage); |
| 170 | } | |
| 171 | 0 | globus_options_help(opts_handle); |
| 172 | ||
| 173 | 0 | if (options->post_banner) |
| 174 | { | |
| 175 | 0 | printf("\n%s\n", options->post_banner); |
| 176 | } | |
| 177 | 0 | return globus_error_put(globus_error_construct_error( |
| 178 | NULL, | |
| 179 | NULL, | |
| 180 | GLOBUS_OPTIONS_HELP, | |
| 181 | __FILE__, | |
| 182 | "globus_l_wsrf_options_help", | |
| 183 | __LINE__, | |
| 184 | "Help")); | |
| 185 | } | |
| 186 | /* globus_l_wsrf_options_set_help() */ | |
| 187 | ||
| 188 | static | |
| 189 | globus_result_t | |
| 190 | globus_l_wsrf_options_set_usage( | |
| 191 | globus_options_handle_t opts_handle, | |
| 192 | char * cmd, | |
| 193 | char * param[], | |
| 194 | void * arg, | |
| 195 | int * out_params_used) | |
| 196 | 0 | { |
| 197 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 198 | const char * tmp; | |
| 199 | ||
| 200 | 0 | if (options->application_name) |
| 201 | { | |
| 202 | 0 | tmp = strrchr(options->application_name, '/'); |
| 203 | 0 | tmp = tmp ? tmp+1 : options->application_name; |
| 204 | } | |
| 205 | else | |
| 206 | { | |
| 207 | 0 | tmp = "globus_wsrf_core_tools"; |
| 208 | } | |
| 209 | 0 | if (options->usage) |
| 210 | { | |
| 211 | 0 | printf("Usage: %s %s\n", tmp, options->usage); |
| 212 | } | |
| 213 | 0 | return globus_error_put(globus_error_construct_error( |
| 214 | NULL, | |
| 215 | NULL, | |
| 216 | GLOBUS_OPTIONS_HELP, | |
| 217 | __FILE__, | |
| 218 | "globus_l_wsrf_options_usage", | |
| 219 | __LINE__, | |
| 220 | "usage")); | |
| 221 | } | |
| 222 | /* globus_l_wsrf_options_set_usage() */ | |
| 223 | ||
| 224 | static | |
| 225 | globus_result_t | |
| 226 | globus_l_wsrf_options_set_key( | |
| 227 | globus_options_handle_t opts_handle, | |
| 228 | char * cmd, | |
| 229 | char * param[], | |
| 230 | void * arg, | |
| 231 | int * out_params_used) | |
| 232 | 0 | { |
| 233 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 234 | char * tmp; | |
| 235 | globus_result_t result; | |
| 236 | 0 | char * key = param[0]; |
| 237 | xsd_any * any; | |
| 238 | xsd_string * val; | |
| 239 | ||
| 240 | 0 | if (options->epr && options->epr->ReferenceParameters) |
| 241 | { | |
| 242 | 0 | wsa_ReferenceParametersType_destroy(options->epr->ReferenceParameters); |
| 243 | } | |
| 244 | 0 | else if (!options->epr) |
| 245 | { | |
| 246 | 0 | result = wsa_EndpointReferenceType_init(&options->epr); |
| 247 | ||
| 248 | 0 | if (result != GLOBUS_SUCCESS) |
| 249 | { | |
| 250 | 0 | goto out; |
| 251 | } | |
| 252 | } | |
| 253 | 0 | result = wsa_ReferenceParametersType_init(&options->epr->ReferenceParameters); |
| 254 | 0 | if (result != GLOBUS_SUCCESS) |
| 255 | { | |
| 256 | 0 | goto out; |
| 257 | } | |
| 258 | ||
| 259 | 0 | any = xsd_any_array_push(&options->epr->ReferenceParameters->any); |
| 260 | ||
| 261 | 0 | if (!any) |
| 262 | { | |
| 263 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 264 | ||
| 265 | 0 | goto out; |
| 266 | } | |
| 267 | ||
| 268 | 0 | result = xsd_QName_init(&any->element); |
| 269 | ||
| 270 | 0 | if (result != GLOBUS_SUCCESS) |
| 271 | { | |
| 272 | 0 | goto out; |
| 273 | } | |
| 274 | ||
| 275 | 0 | if (key[0] == '{' && ((tmp = strchr(key, '}')) != NULL)) |
| 276 | { | |
| 277 | 0 | *tmp = '\0'; |
| 278 | /* key is a QName in {Namespace}local form */ | |
| 279 | 0 | any->element->Namespace = globus_libc_strdup(key+1); |
| 280 | 0 | if (any->element->Namespace == NULL) |
| 281 | { | |
| 282 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 283 | ||
| 284 | 0 | goto out; |
| 285 | } | |
| 286 | ||
| 287 | 0 | any->element->local = globus_libc_strdup(tmp+1); |
| 288 | 0 | if (any->element->local == NULL) |
| 289 | { | |
| 290 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 291 | ||
| 292 | 0 | goto out; |
| 293 | } | |
| 294 | } | |
| 295 | else | |
| 296 | { | |
| 297 | 0 | any->element->Namespace = NULL; |
| 298 | 0 | any->element->local = globus_libc_strdup(key);; |
| 299 | 0 | if (any->element->local == NULL) |
| 300 | { | |
| 301 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 302 | ||
| 303 | 0 | goto out; |
| 304 | } | |
| 305 | } | |
| 306 | 0 | any->any_info = &xsd_string_info; |
| 307 | 0 | result = xsd_string_init(&val); |
| 308 | 0 | if (result != GLOBUS_SUCCESS) |
| 309 | { | |
| 310 | 0 | goto out; |
| 311 | } | |
| 312 | 0 | any->value = val; |
| 313 | 0 | result = xsd_string_copy_contents( |
| 314 | val, | |
| 315 | ¶m[1]); | |
| 316 | if (result != GLOBUS_SUCCESS) | |
| 317 | { | |
| 318 | 0 | goto out; |
| 319 | } | |
| 320 | ||
| 321 | 0 | out: |
| 322 | 0 | return result; |
| 323 | } | |
| 324 | /* globus_l_wsrf_options_set_key() */ | |
| 325 | ||
| 326 | #if 0 | |
| 327 | static | |
| 328 | globus_result_t | |
| 329 | globus_l_wsrf_options_set_context_lifetime( | |
| 330 | globus_options_handle_t opts_handle, | |
| 331 | char * cmd, | |
| 332 | char * param[], | |
| 333 | void * arg, | |
| 334 | int * out_params_used) | |
| 335 | { | |
| 336 | return GLOBUS_FAILURE; | |
| 337 | } | |
| 338 | /* globus_l_wsrf_options_set_context_lifetime() */ | |
| 339 | #endif | |
| 340 | ||
| 341 | static | |
| 342 | globus_result_t | |
| 343 | globus_l_wsrf_options_set_security_mech( | |
| 344 | globus_options_handle_t opts_handle, | |
| 345 | char * cmd, | |
| 346 | char * param[], | |
| 347 | void * arg, | |
| 348 | int * out_params_used) | |
| 349 | 0 | { |
| 350 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 351 | globus_result_t result; | |
| 352 | ||
| 353 | 0 | if (strcmp(param[0], "msg") == 0) |
| 354 | { | |
| 355 | 0 | result = globus_soap_message_attr_set( |
| 356 | options->attr, | |
| 357 | GLOBUS_SOAP_MESSAGE_AUTHENTICATION_METHOD_KEY, | |
| 358 | NULL, | |
| 359 | NULL, | |
| 360 | (void *) GLOBUS_SOAP_MESSAGE_AUTH_SECURE_MESSAGE); | |
| 361 | } | |
| 362 | 0 | else if (strcmp(param[0], "conv") == 0) |
| 363 | { | |
| 364 | 0 | result = globus_soap_message_attr_set( |
| 365 | options->attr, | |
| 366 | GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_KEY, | |
| 367 | NULL, | |
| 368 | NULL, | |
| 369 | (void *) GLOBUS_SOAP_MESSAGE_AUTH_SECURE_CONVERSATION); | |
| 370 | } | |
| 371 | else | |
| 372 | { | |
| 373 | 0 | result = globus_error_put(globus_error_construct_error( |
| 374 | NULL, | |
| 375 | NULL, | |
| 376 | GLOBUS_OPTIONS_INVALID_PARAMETER, | |
| 377 | __FILE__, | |
| 378 | "globus_l_wsrf_options_set_security_mech", | |
| 379 | __LINE__, | |
| 380 | "Unknown security mechanism %s.", | |
| 381 | param[0])); | |
| 382 | } | |
| 383 | 0 | return GLOBUS_SUCCESS; |
| 384 | } | |
| 385 | /* globus_l_wsrf_options_set_security_mech() */ | |
| 386 | ||
| 387 | static | |
| 388 | globus_result_t | |
| 389 | globus_l_wsrf_options_set_protection( | |
| 390 | globus_options_handle_t opts_handle, | |
| 391 | char * cmd, | |
| 392 | char * param[], | |
| 393 | void * arg, | |
| 394 | int * out_params_used) | |
| 395 | 0 | { |
| 396 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 397 | globus_result_t result; | |
| 398 | ||
| 399 | 0 | if (strcmp(param[0], "sig") == 0) |
| 400 | { | |
| 401 | 0 | result = globus_soap_message_attr_set( |
| 402 | options->attr, | |
| 403 | GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_KEY, | |
| 404 | NULL, | |
| 405 | NULL, | |
| 406 | (void *) GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_INTEGRITY); | |
| 407 | } | |
| 408 | 0 | else if (strcmp(param[0], "enc") == 0) |
| 409 | { | |
| 410 | 0 | result = globus_soap_message_attr_set( |
| 411 | options->attr, | |
| 412 | GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_KEY, | |
| 413 | NULL, | |
| 414 | NULL, | |
| 415 | (void *) GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_PRIVACY); | |
| 416 | } | |
| 417 | else | |
| 418 | { | |
| 419 | 0 | return GLOBUS_FAILURE; |
| 420 | } | |
| 421 | 0 | return GLOBUS_SUCCESS; |
| 422 | } | |
| 423 | /* globus_l_wsrf_options_set_protection() */ | |
| 424 | ||
| 425 | static | |
| 426 | globus_result_t | |
| 427 | globus_l_wsrf_options_set_service( | |
| 428 | globus_options_handle_t opts_handle, | |
| 429 | char * cmd, | |
| 430 | char * param[], | |
| 431 | void * arg, | |
| 432 | int * out_params_used) | |
| 433 | 54 | { |
| 434 | 54 | globus_i_wsrf_options_handle_t * options = arg; |
| 435 | globus_result_t result; | |
| 436 | ||
| 437 | 54 | if (options->epr && options->epr->Address.base_value) |
| 438 | { | |
| 439 | 0 | wsa_AttributedURIType_destroy(&options->epr->Address); |
| 440 | } | |
| 441 | 54 | else if (!options->epr) |
| 442 | { | |
| 443 | 54 | result = wsa_EndpointReferenceType_init(&options->epr); |
| 444 | ||
| 445 | 54 | if (result != GLOBUS_SUCCESS) |
| 446 | { | |
| 447 | 0 | goto out; |
| 448 | } | |
| 449 | } | |
| 450 | 54 | result = xsd_anyURI_copy_contents( |
| 451 | &options->epr->Address.base_value, | |
| 452 | param); | |
| 453 | ||
| 454 | 54 | out: |
| 455 | 54 | return result; |
| 456 | } | |
| 457 | /* globus_l_wsrf_options_set_service() */ | |
| 458 | ||
| 459 | static | |
| 460 | globus_result_t | |
| 461 | globus_l_reltime_copy( | |
| 462 | void ** new_attr, | |
| 463 | const void * attr) | |
| 464 | 0 | { |
| 465 | 0 | *new_attr = malloc(sizeof(globus_reltime_t)); |
| 466 | ||
| 467 | 0 | memcpy(*new_attr, attr, sizeof(globus_reltime_t)); |
| 468 | ||
| 469 | 0 | return GLOBUS_SUCCESS; |
| 470 | } | |
| 471 | /* globus_l_reltime_copy() */ | |
| 472 | ||
| 473 | static | |
| 474 | globus_result_t | |
| 475 | globus_l_wsrf_options_set_timeout( | |
| 476 | globus_options_handle_t opts_handle, | |
| 477 | char * cmd, | |
| 478 | char * param[], | |
| 479 | void * arg, | |
| 480 | int * out_params_used) | |
| 481 | 0 | { |
| 482 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 483 | globus_reltime_t timeout; | |
| 484 | globus_result_t result; | |
| 485 | ||
| 486 | 0 | timeout.tv_sec = atoi(param[0]); |
| 487 | 0 | timeout.tv_usec = 0; |
| 488 | ||
| 489 | 0 | result = globus_soap_message_attr_set( |
| 490 | options->attr, | |
| 491 | GLOBUS_SOAP_MESSAGE_TIMEOUT_KEY, | |
| 492 | globus_l_reltime_copy, | |
| 493 | free, | |
| 494 | &timeout); | |
| 495 | ||
| 496 | 0 | return result; |
| 497 | } | |
| 498 | /* globus_l_wsrf_options_set_timeout() */ | |
| 499 | ||
| 500 | static | |
| 501 | globus_result_t | |
| 502 | globus_l_wsrf_options_set_cert_key_files( | |
| 503 | globus_options_handle_t opts_handle, | |
| 504 | char * cmd, | |
| 505 | char * param[], | |
| 506 | void * arg, | |
| 507 | int * out_params_used) | |
| 508 | 0 | { |
| 509 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 510 | char * b; | |
| 511 | FILE * cert_in; | |
| 512 | FILE * key_in; | |
| 513 | size_t cert_size; | |
| 514 | size_t key_size; | |
| 515 | int rc; | |
| 516 | globus_result_t result; | |
| 517 | gss_cred_id_t cred; | |
| 518 | OM_uint32 maj_stat; | |
| 519 | OM_uint32 min_stat; | |
| 520 | gss_buffer_desc import_buffer; | |
| 521 | ||
| 522 | 0 | cert_in = fopen(param[0], "r"); |
| 523 | 0 | if (cert_in == NULL) |
| 524 | { | |
| 525 | 0 | result = globus_error_put(globus_error_construct_error( |
| 526 | NULL, | |
| 527 | NULL, | |
| 528 | GLOBUS_OPTIONS_INVALID_PARAMETER, | |
| 529 | __FILE__, | |
| 530 | "globus_l_wsrf_options_set_cert_key_files", | |
| 531 | __LINE__, | |
| 532 | "Unable to open cert file %s for reading.", | |
| 533 | param[0])); | |
| 534 | ||
| 535 | 0 | goto out; |
| 536 | } | |
| 537 | ||
| 538 | 0 | if (fseek(cert_in, 0, SEEK_END) != 0) |
| 539 | { | |
| 540 | 0 | result = globus_error_put(globus_error_construct_error( |
| 541 | NULL, | |
| 542 | NULL, | |
| 543 | GLOBUS_OPTIONS_INVALID_PARAMETER, | |
| 544 | __FILE__, | |
| 545 | "globus_l_wsrf_options_set_cert_key_files", | |
| 546 | __LINE__, | |
| 547 | "Unable to seek cert file %s.", | |
| 548 | param[0])); | |
| 549 | 0 | goto close_cert_out; |
| 550 | } | |
| 551 | 0 | cert_size = ftell(cert_in); |
| 552 | 0 | rewind(cert_in); |
| 553 | ||
| 554 | 0 | key_in = fopen(param[1], "r"); |
| 555 | 0 | if (key_in == NULL) |
| 556 | { | |
| 557 | 0 | result = globus_error_put(globus_error_construct_error( |
| 558 | NULL, | |
| 559 | NULL, | |
| 560 | GLOBUS_OPTIONS_INVALID_PARAMETER, | |
| 561 | __FILE__, | |
| 562 | "globus_l_wsrf_options_set_cert_key_files", | |
| 563 | __LINE__, | |
| 564 | "Unable to open key file %s for reading.", | |
| 565 | param[1])); | |
| 566 | 0 | goto close_cert_out; |
| 567 | } | |
| 568 | ||
| 569 | 0 | if (fseek(key_in, 0, SEEK_END) != 0) |
| 570 | { | |
| 571 | 0 | result = globus_error_put(globus_error_construct_error( |
| 572 | NULL, | |
| 573 | NULL, | |
| 574 | GLOBUS_OPTIONS_INVALID_PARAMETER, | |
| 575 | __FILE__, | |
| 576 | "globus_l_wsrf_options_set_cert_key_files", | |
| 577 | __LINE__, | |
| 578 | "Unable to seek key file %s.", | |
| 579 | param[1])); | |
| 580 | ||
| 581 | 0 | goto close_key_file_out; |
| 582 | } | |
| 583 | 0 | key_size = ftell(key_in); |
| 584 | 0 | rewind(key_in); |
| 585 | ||
| 586 | 0 | b = malloc(cert_size+key_size+2); |
| 587 | 0 | if (!b) |
| 588 | { | |
| 589 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 590 | ||
| 591 | 0 | goto close_key_file_out; |
| 592 | } | |
| 593 | 0 | rc = fread(b, 1, cert_size, cert_in); |
| 594 | 0 | b[rc++] = '\n'; |
| 595 | 0 | rc += fread(b+rc, 1, key_size, key_in); |
| 596 | 0 | b[rc++] = '\0'; |
| 597 | ||
| 598 | 0 | import_buffer.value = b; |
| 599 | ||
| 600 | 0 | import_buffer.length = strlen(b); |
| 601 | ||
| 602 | 0 | maj_stat = gss_import_cred( |
| 603 | &min_stat, | |
| 604 | &cred, | |
| 605 | GSS_C_NO_OID, | |
| 606 | GSS_IMPEXP_OPAQUE_FORM, | |
| 607 | &import_buffer, | |
| 608 | 0, | |
| 609 | NULL); | |
| 610 | 0 | if (maj_stat != GSS_S_COMPLETE) |
| 611 | { | |
| 612 | 0 | result = globus_error_put( |
| 613 | globus_error_construct_gssapi_error(NULL, NULL, maj_stat, min_stat)); | |
| 614 | 0 | goto free_import_buffer_out; |
| 615 | ||
| 616 | } | |
| 617 | ||
| 618 | /* This will leak the cred because there is no cred copy function */ | |
| 619 | 0 | result = globus_soap_message_attr_set( |
| 620 | options->attr, | |
| 621 | GLOBUS_SOAP_MESSAGE_USER_CREDENTIAL_KEY, | |
| 622 | NULL, | |
| 623 | NULL, | |
| 624 | cred); | |
| 625 | ||
| 626 | 0 | free_import_buffer_out: |
| 627 | 0 | free(import_buffer.value); |
| 628 | 0 | close_key_file_out: |
| 629 | 0 | fclose(key_in); |
| 630 | 0 | close_cert_out: |
| 631 | 0 | fclose(cert_in); |
| 632 | 0 | out: |
| 633 | 0 | return result; |
| 634 | } | |
| 635 | /* globus_l_wsrf_options_set_cert_key_files() */ | |
| 636 | ||
| 637 | static | |
| 638 | globus_result_t | |
| 639 | globus_l_wsrf_options_set_proxy_file_name( | |
| 640 | globus_options_handle_t opts_handle, | |
| 641 | char * cmd, | |
| 642 | char * param[], | |
| 643 | void * arg, | |
| 644 | int * out_params_used) | |
| 645 | 0 | { |
| 646 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 647 | globus_result_t result; | |
| 648 | gss_cred_id_t cred; | |
| 649 | OM_uint32 maj_stat; | |
| 650 | OM_uint32 min_stat; | |
| 651 | gss_buffer_desc import_buffer; | |
| 652 | ||
| 653 | 0 | import_buffer.value = globus_common_create_string( |
| 654 | "X509_USER_PROXY=%s", | |
| 655 | param[0]); | |
| 656 | 0 | if (import_buffer.value == NULL) |
| 657 | { | |
| 658 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 659 | ||
| 660 | 0 | goto out; |
| 661 | } | |
| 662 | 0 | import_buffer.length = strlen(import_buffer.value); |
| 663 | ||
| 664 | 0 | maj_stat = gss_import_cred( |
| 665 | &min_stat, | |
| 666 | &cred, | |
| 667 | GSS_C_NO_OID, | |
| 668 | GSS_IMPEXP_MECH_SPECIFIC, | |
| 669 | &import_buffer, | |
| 670 | 0, | |
| 671 | NULL); | |
| 672 | 0 | if (maj_stat != GSS_S_COMPLETE) |
| 673 | { | |
| 674 | 0 | result = globus_error_put( |
| 675 | globus_error_construct_gssapi_error(NULL, NULL, maj_stat, min_stat)); | |
| 676 | 0 | goto free_import_buffer_out; |
| 677 | ||
| 678 | } | |
| 679 | ||
| 680 | /* This will leak the cred because there is no cred copy function */ | |
| 681 | 0 | result = globus_soap_message_attr_set( |
| 682 | options->attr, | |
| 683 | GLOBUS_SOAP_MESSAGE_USER_CREDENTIAL_KEY, | |
| 684 | NULL, | |
| 685 | NULL, | |
| 686 | cred); | |
| 687 | ||
| 688 | 0 | free_import_buffer_out: |
| 689 | 0 | free(import_buffer.value); |
| 690 | 0 | out: |
| 691 | 0 | return result; |
| 692 | } | |
| 693 | /* globus_l_wsrf_options_set_proxy_file_name() */ | |
| 694 | ||
| 695 | static | |
| 696 | globus_result_t | |
| 697 | globus_l_wsrf_options_set_authorization( | |
| 698 | globus_options_handle_t opts_handle, | |
| 699 | char * cmd, | |
| 700 | char * param[], | |
| 701 | void * arg, | |
| 702 | int * out_params_used) | |
| 703 | 0 | { |
| 704 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 705 | globus_result_t result; | |
| 706 | ||
| 707 | 0 | if (strcmp(param[0], "self") == 0) |
| 708 | { | |
| 709 | 0 | result = globus_soap_message_attr_set( |
| 710 | options->attr, | |
| 711 | GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY, | |
| 712 | NULL, | |
| 713 | NULL, | |
| 714 | (void *) GLOBUS_SOAP_MESSAGE_AUTHZ_SELF); | |
| 715 | } | |
| 716 | 0 | else if (strcmp(param[0], "host") == 0) |
| 717 | { | |
| 718 | 0 | result = globus_soap_message_attr_set( |
| 719 | options->attr, | |
| 720 | GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY, | |
| 721 | NULL, | |
| 722 | NULL, | |
| 723 | (void *) GLOBUS_SOAP_MESSAGE_AUTHZ_HOST); | |
| 724 | } | |
| 725 | 0 | else if (strcmp(param[0], "hostSelf") == 0) |
| 726 | { | |
| 727 | 0 | result = globus_soap_message_attr_set( |
| 728 | options->attr, | |
| 729 | GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY, | |
| 730 | NULL, | |
| 731 | NULL, | |
| 732 | (void *) GLOBUS_SOAP_MESSAGE_AUTHZ_HOST_SELF); | |
| 733 | } | |
| 734 | 0 | else if (strcmp(param[0], "none") == 0) |
| 735 | { | |
| 736 | 0 | result = globus_soap_message_attr_set( |
| 737 | options->attr, | |
| 738 | GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY, | |
| 739 | NULL, | |
| 740 | NULL, | |
| 741 | (void *) GLOBUS_SOAP_MESSAGE_AUTHZ_NONE); | |
| 742 | } | |
| 743 | else | |
| 744 | { | |
| 745 | gss_buffer_desc buff; | |
| 746 | gss_name_t name; | |
| 747 | OM_uint32 min_stat; | |
| 748 | OM_uint32 maj_stat; | |
| 749 | ||
| 750 | /* Subject */ | |
| 751 | 0 | result = globus_soap_message_attr_set( |
| 752 | options->attr, | |
| 753 | GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY, | |
| 754 | NULL, | |
| 755 | NULL, | |
| 756 | (void *) GLOBUS_SOAP_MESSAGE_AUTHZ_IDENTITY); | |
| 757 | ||
| 758 | 0 | buff.value = param[0]; |
| 759 | 0 | buff.length = strlen(buff.value); |
| 760 | ||
| 761 | 0 | maj_stat = gss_import_name( |
| 762 | &min_stat, | |
| 763 | &buff, | |
| 764 | GSS_C_NO_OID, | |
| 765 | &name); | |
| 766 | 0 | if (maj_stat != GSS_S_COMPLETE) |
| 767 | { | |
| 768 | globus_object_t * err; | |
| 769 | ||
| 770 | 0 | err = globus_error_construct_gssapi_error( |
| 771 | GLOBUS_WSRF_CORE_TOOLS_MODULE, | |
| 772 | NULL, | |
| 773 | maj_stat, | |
| 774 | min_stat); | |
| 775 | ||
| 776 | 0 | result = GlobusSoapMessageErrorFailedTransport( |
| 777 | globus_error_put(err), | |
| 778 | "Failed to import target subject name"); | |
| 779 | } | |
| 780 | else | |
| 781 | { | |
| 782 | 0 | result = globus_soap_message_attr_set( |
| 783 | options->attr, | |
| 784 | GLOBUS_SOAP_MESSAGE_AUTHZ_TARGET_NAME_KEY, | |
| 785 | NULL, | |
| 786 | NULL, | |
| 787 | name); | |
| 788 | } | |
| 789 | } | |
| 790 | ||
| 791 | 0 | return result; |
| 792 | } | |
| 793 | /* globus_l_wsrf_options_set_authorization() */ | |
| 794 | ||
| 795 | static | |
| 796 | globus_result_t | |
| 797 | globus_l_wsrf_options_set_version( | |
| 798 | globus_options_handle_t opts_handle, | |
| 799 | char * cmd, | |
| 800 | char * param[], | |
| 801 | void * arg, | |
| 802 | int * out_params_used) | |
| 803 | 0 | { |
| 804 | 0 | globus_i_wsrf_options_handle_t * options = arg; |
| 805 | const char * tmp; | |
| 806 | const globus_version_t * version; | |
| 807 | ||
| 808 | 0 | if (options->application_name) |
| 809 | { | |
| 810 | 0 | tmp = strrchr(options->application_name,'/'); |
| 811 | 0 | tmp = tmp ? tmp+1 : options->application_name; |
| 812 | } | |
| 813 | else | |
| 814 | { | |
| 815 | 0 | tmp = "globus_wsrf_core_tools"; |
| 816 | } | |
| 817 | ||
| 818 | 0 | if (options->application_version) |
| 819 | { | |
| 820 | 0 | version = options->application_version; |
| 821 | } | |
| 822 | else | |
| 823 | { | |
| 824 | 0 | version = &local_version; |
| 825 | } | |
| 826 | ||
| 827 | 0 | globus_version_print( |
| 828 | tmp, | |
| 829 | version, | |
| 830 | stdout, | |
| 831 | 1); | |
| 832 | ||
| 833 | 0 | return globus_error_put(globus_error_construct_error( |
| 834 | NULL, | |
| 835 | NULL, | |
| 836 | GLOBUS_OPTIONS_HELP, | |
| 837 | __FILE__, | |
| 838 | "globus_l_wsrf_options_set_version", | |
| 839 | __LINE__, | |
| 840 | "Program versions")); | |
| 841 | } | |
| 842 | /* globus_l_wsrf_options_set_version() */ | |
| 843 | ||
| 844 | static | |
| 845 | globus_result_t | |
| 846 | globus_l_wsrf_options_set_versions( | |
| 847 | globus_options_handle_t opts_handle, | |
| 848 | char * cmd, | |
| 849 | char * param[], | |
| 850 | void * arg, | |
| 851 | int * out_params_used) | |
| 852 | 0 | { |
| 853 | 0 | globus_module_print_activated_versions( |
| 854 | stdout, | |
| 855 | 1); | |
| 856 | ||
| 857 | 0 | return globus_error_put(globus_error_construct_error( |
| 858 | NULL, | |
| 859 | NULL, | |
| 860 | GLOBUS_OPTIONS_HELP, | |
| 861 | __FILE__, | |
| 862 | "globus_l_wsrf_options_set_versions", | |
| 863 | __LINE__, | |
| 864 | "Program versions")); | |
| 865 | ||
| 866 | } | |
| 867 | /* globus_l_wsrf_options_set_versions() */ | |
| 868 | #endif /* GLOBUS_DONT_DOCUMENT_INTERNAL */ | |
| 869 | ||
| 870 | /** | |
| 871 | * @page globus_wsrf_options_options Common WSRF Client Options | |
| 872 | * | |
| 873 | * @ingroup globus_wsrf_options | |
| 874 | * <pre> | |
| 875 | * -a | --anonymous Use anonymous authentication. Requires either -m | |
| 876 | * 'conv' or transport (https) security. | |
| 877 | * -d | --debug Enable debug mode | |
| 878 | * -e | --eprFile FILENAME Load service EPR from FILENAME | |
| 879 | * -h | --help Print this help message. | |
| 880 | * -k | --key KEYNAME VALUE Set resource key in service EPR to be named | |
| 881 | * KEYNAME with VALUE as its value. | |
| 882 | * -m | --securityMech TYPE Set authentication mechanism. TYPE is one of | |
| 883 | * 'msg' for WS-SecureMessage or 'conv' for | |
| 884 | * WS-SecureConversation. | |
| 885 | * -p | --protection LEVEL Set message protection level. LEVEL is one of | |
| 886 | * 'sig' for digital signature or 'enc' for | |
| 887 | * encryption. | |
| 888 | * -s | --service ENDPOINT Set ENDPOINT the service URL to use. | |
| 889 | * -t | --timeout SECONDS Set client timeout to SECONDS. | |
| 890 | * -u | --usage Print short usage message. | |
| 891 | * -V | --version Show version information and exit. | |
| 892 | * -v | --certKeyFiles CERTIFICATE-FILENAME KEY-FILENAME | |
| 893 | * Use credentials located in CERTIFICATE-FILENAME | |
| 894 | * and KEY-FILENAME. The key file must be | |
| 895 | * unencrypted. | |
| 896 | * -x | --proxyFilename FILENAME | |
| 897 | * Use proxy credentials located in FILENAME | |
| 898 | * -z | --authorization TYPE Set authorization mode. TYPE can be 'self', | |
| 899 | * 'host', 'hostSelf', 'none', or a string | |
| 900 | * specifying the identity of the remote party. | |
| 901 | * --versions Show version information for all loaded modules | |
| 902 | * and exit. | |
| 903 | * </pre> | |
| 904 | */ | |
| 905 | #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL | |
| 906 | globus_options_entry_t | |
| 907 | globus_i_wsrf_common_options_table[] = | |
| 908 | { | |
| 909 | { | |
| 910 | "anonymous", | |
| 911 | "a", | |
| 912 | NULL, | |
| 913 | NULL, | |
| 914 | "Use anonymous authentication. Requires either -m 'conv' or transport (https) " | |
| 915 | "security.", | |
| 916 | 0, | |
| 917 | globus_l_wsrf_options_set_anonymous | |
| 918 | }, | |
| 919 | #if 0 | |
| 920 | { | |
| 921 | "serviceCertificate", | |
| 922 | "c", | |
| 923 | NULL, | |
| 924 | "FILENAME", | |
| 925 | "Use server's certificate located in FILENAME for encryption with GSI Secure " | |
| 926 | "Message", | |
| 927 | 1, | |
| 928 | globus_l_wsrf_options_set_server_certificate | |
| 929 | }, | |
| 930 | #endif | |
| 931 | { | |
| 932 | "debug", | |
| 933 | "d", | |
| 934 | NULL, | |
| 935 | NULL, | |
| 936 | "Enable debug mode", | |
| 937 | 0, | |
| 938 | globus_l_wsrf_options_set_debug | |
| 939 | }, | |
| 940 | { | |
| 941 | "eprFile", | |
| 942 | "e", | |
| 943 | NULL, | |
| 944 | "FILENAME", | |
| 945 | "Load service EPR from FILENAME", | |
| 946 | 1, | |
| 947 | globus_l_wsrf_options_set_epr | |
| 948 | }, | |
| 949 | #if 0 | |
| 950 | { | |
| 951 | "descriptor", | |
| 952 | "f", | |
| 953 | NULL, | |
| 954 | "FILENAME", | |
| 955 | "Read client security descriptor from FILENAME", | |
| 956 | 1, | |
| 957 | globus_l_wsrf_options_set_descriptor | |
| 958 | }, | |
| 959 | #endif | |
| 960 | #if 0 | |
| 961 | { | |
| 962 | "delegation", | |
| 963 | "g", | |
| 964 | NULL, | |
| 965 | "MODE", | |
| 966 | "Delegate credentials to service. MODE can be either 'limited' or 'full'. " | |
| 967 | "Requires -m 'conv' option.", | |
| 968 | 1, | |
| 969 | globus_l_wsrf_options_set_delegation | |
| 970 | }, | |
| 971 | #endif | |
| 972 | { | |
| 973 | "help", | |
| 974 | "h", | |
| 975 | NULL, | |
| 976 | NULL, | |
| 977 | "Print this help message.", | |
| 978 | 0, | |
| 979 | globus_l_wsrf_options_set_help | |
| 980 | }, | |
| 981 | { | |
| 982 | "usage", | |
| 983 | "u", | |
| 984 | NULL, | |
| 985 | NULL, | |
| 986 | "Print short usage message.", | |
| 987 | 0, | |
| 988 | globus_l_wsrf_options_set_usage | |
| 989 | }, | |
| 990 | { | |
| 991 | "key", | |
| 992 | "k", | |
| 993 | NULL, | |
| 994 | "KEYNAME VALUE", | |
| 995 | "Set resource key in service EPR to be named KEYNAME with VALUE as its value.", | |
| 996 | 2, | |
| 997 | globus_l_wsrf_options_set_key | |
| 998 | }, | |
| 999 | #if 0 | |
| 1000 | { | |
| 1001 | "contextLifetime", | |
| 1002 | "l", | |
| 1003 | NULL, | |
| 1004 | "SECONDS?", | |
| 1005 | "Set lifetime of GSI security context.", | |
| 1006 | 1, | |
| 1007 | globus_l_wsrf_options_set_context_lifetime | |
| 1008 | }, | |
| 1009 | #endif | |
| 1010 | { | |
| 1011 | "securityMech", | |
| 1012 | "m", | |
| 1013 | NULL, | |
| 1014 | "TYPE", | |
| 1015 | "Set authentication mechanism. TYPE is one of 'msg' for WS-SecureMessage or " | |
| 1016 | "'conv' for WS-SecureConversation.", | |
| 1017 | 1, | |
| 1018 | globus_l_wsrf_options_set_security_mech | |
| 1019 | }, | |
| 1020 | { | |
| 1021 | "protection", | |
| 1022 | "p", | |
| 1023 | NULL, | |
| 1024 | "LEVEL", | |
| 1025 | "Set message protection level. LEVEL is one of 'sig' for digital signature or " | |
| 1026 | "'enc' for encryption. The default is 'sig'.", | |
| 1027 | 1, | |
| 1028 | globus_l_wsrf_options_set_protection | |
| 1029 | }, | |
| 1030 | { | |
| 1031 | "service", | |
| 1032 | "s", | |
| 1033 | NULL, | |
| 1034 | "ENDPOINT", | |
| 1035 | "Set ENDPOINT the service URL to use.", | |
| 1036 | 1, | |
| 1037 | globus_l_wsrf_options_set_service | |
| 1038 | }, | |
| 1039 | { | |
| 1040 | "timeout", | |
| 1041 | "t", | |
| 1042 | NULL, | |
| 1043 | "SECONDS", | |
| 1044 | "Set client timeout to SECONDS.", | |
| 1045 | 1, | |
| 1046 | globus_l_wsrf_options_set_timeout | |
| 1047 | }, | |
| 1048 | { | |
| 1049 | "certKeyFiles", | |
| 1050 | "v", | |
| 1051 | NULL, | |
| 1052 | "CERTIFICATE-FILENAME KEY-FILENAME", | |
| 1053 | "Use credentials located in CERTIFICATE-FILENAME and KEY-FILENAME. The key file " | |
| 1054 | "must be unencrypted.", | |
| 1055 | 2, | |
| 1056 | globus_l_wsrf_options_set_cert_key_files | |
| 1057 | }, | |
| 1058 | { | |
| 1059 | "proxyFilename", | |
| 1060 | "x", | |
| 1061 | NULL, | |
| 1062 | "FILENAME", | |
| 1063 | "Use proxy credentials located in FILENAME", | |
| 1064 | 1, | |
| 1065 | globus_l_wsrf_options_set_proxy_file_name | |
| 1066 | }, | |
| 1067 | { | |
| 1068 | "authorization", | |
| 1069 | "z", | |
| 1070 | NULL, | |
| 1071 | "TYPE", | |
| 1072 | "Set authorization mode. TYPE can be 'self', 'host', 'hostSelf', " | |
| 1073 | "'none', or a string specifying the identity of the remote party. " | |
| 1074 | "The default is 'hostSelf'.", | |
| 1075 | 1, | |
| 1076 | globus_l_wsrf_options_set_authorization | |
| 1077 | }, | |
| 1078 | { | |
| 1079 | "version", | |
| 1080 | "V", | |
| 1081 | NULL, | |
| 1082 | NULL, | |
| 1083 | "Show version information and exit.", | |
| 1084 | 0, | |
| 1085 | globus_l_wsrf_options_set_version | |
| 1086 | }, | |
| 1087 | { | |
| 1088 | "versions", | |
| 1089 | NULL, | |
| 1090 | NULL, | |
| 1091 | NULL, | |
| 1092 | "Show version information for all loaded modules and exit.", | |
| 1093 | 0, | |
| 1094 | globus_l_wsrf_options_set_versions | |
| 1095 | }, | |
| 1096 | GLOBUS_OPTIONS_END | |
| 1097 | }; |