Skip to content

Commit f7a1f9b

Browse files
committed
Switch proxy creation to use Globus library calls. Equivalent to proxy-tools.patch from HTCondor.
1 parent eca1154 commit f7a1f9b

File tree

3 files changed

+168
-60
lines changed

3 files changed

+168
-60
lines changed

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ if test $have_globus = no; then
245245
PKG_CHECK_MODULES(GLOBUS_GSI_UTILS, globus-gsi-cert-utils, , have_globus=no)
246246
PKG_CHECK_MODULES(GLOBUS_GSS_ASSIST, globus-gss-assist, , have_globus=no)
247247
PKG_CHECK_MODULES(GLOBUS_GSI_SYSCFG, globus-gsi-sysconfig, , have_globus=no)
248+
PKG_CHECK_MODULES(GLOBUS_GSSAPI_GSI, globus-gssapi-gsi, , have_globus=no)
248249
fi
249250
AC_MSG_RESULT(["GLOBUS found: $have_globus"])
250251
AM_CONDITIONAL([HAVE_GLOBUS], [test "x$bprserver" == "xyes" -a "x$have_globus" == "xyes"])

src/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ blahpd_SOURCES = main.c $(common_sources)
5757

5858
blahpd_daemon_SOURCES = main_daemon.c $(common_sources)
5959

60-
blahpd_LDADD = $(CLASSAD_LIBS)
60+
blahpd_LDADD = $(CLASSAD_LIBS) $(GLOBUS_GSSSAPI_GSI_LIBS) $(GLOBUS_GSS_ASSIST_LIBS)
6161

6262
blahpd_daemon_LDADD = $(blahpd_LDADD)
6363

src/server.c

+166-59
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
#include <fcntl.h>
8585
#include <signal.h>
8686

87+
#include "globus_gsi_credential.h"
88+
#include "globus_gsi_proxy.h"
89+
8790
#include "blahpd.h"
8891
#include "config.h"
8992
#include "job_registry.h"
@@ -2591,14 +2594,167 @@ set_cmd_list_option(char **command, classad_context cad, const char *attribute,
25912594
if (to_append) free (to_append);
25922595
return(result);
25932596
}
2597+
2598+
const char *grid_proxy_errmsg = NULL;
2599+
2600+
int activate_globus()
2601+
{
2602+
static int active = 0;
2603+
2604+
if (active) {
2605+
return 0;
2606+
}
2607+
2608+
if ( globus_thread_set_model( "pthread" ) ) {
2609+
grid_proxy_errmsg = "failed to activate Globus";
2610+
return -1;
2611+
}
2612+
2613+
if ( globus_module_activate(GLOBUS_GSI_CREDENTIAL_MODULE) ) {
2614+
grid_proxy_errmsg = "failed to activate Globus";
2615+
return -1;
2616+
}
2617+
2618+
if ( globus_module_activate(GLOBUS_GSI_PROXY_MODULE) ) {
2619+
grid_proxy_errmsg = "failed to activate Globus";
2620+
return -1;
2621+
}
2622+
2623+
active = 1;
2624+
return 0;
2625+
}
2626+
2627+
/* Returns lifetime left on proxy, in seconds.
2628+
* 0 means proxy is expired.
2629+
* -1 means an error occurred.
2630+
*/
2631+
int grid_proxy_info(const char *proxy_filename)
2632+
{
2633+
globus_gsi_cred_handle_t handle = NULL;
2634+
time_t time_left = -1;
2635+
2636+
if ( activate_globus() < 0 ) {
2637+
return -1;
2638+
}
2639+
2640+
if (globus_gsi_cred_handle_init(&handle, NULL)) {
2641+
grid_proxy_errmsg = "failed to initialize Globus data structures";
2642+
goto cleanup;
2643+
}
2644+
2645+
// We should have a proxy file, now, try to read it
2646+
if (globus_gsi_cred_read_proxy(handle, proxy_filename)) {
2647+
grid_proxy_errmsg = "unable to read proxy file";
2648+
goto cleanup;
2649+
}
2650+
2651+
if (globus_gsi_cred_get_lifetime(handle, &time_left)) {
2652+
grid_proxy_errmsg = "unable to extract expiration time";
2653+
goto cleanup;
2654+
}
2655+
2656+
if ( time_left < 0 ) {
2657+
time_left = 0;
2658+
}
2659+
2660+
cleanup:
2661+
if (handle) {
2662+
globus_gsi_cred_handle_destroy(handle);
2663+
}
2664+
2665+
return time_left;
2666+
}
2667+
2668+
/* Writes new proxy derived from existing one. Argument lifetime is the
2669+
* number of seconds until expiration for the new proxy. A 0 lifetime
2670+
* means the same expiration time as the source proxy.
2671+
* Returns 0 on success and -1 on error.
2672+
*/
2673+
int grid_proxy_init(const char *src_filename, char *dst_filename,
2674+
int lifetime)
2675+
{
2676+
globus_gsi_cred_handle_t src_handle = NULL;
2677+
globus_gsi_cred_handle_t dst_handle = NULL;
2678+
globus_gsi_proxy_handle_t dst_proxy_handle = NULL;
2679+
int rc = -1;
2680+
time_t src_time_left = -1;
2681+
globus_gsi_cert_utils_cert_type_t cert_type = GLOBUS_GSI_CERT_UTILS_TYPE_LIMITED_PROXY;
2682+
2683+
if ( activate_globus() < 0 ) {
2684+
return -1;
2685+
}
2686+
2687+
if (globus_gsi_cred_handle_init(&src_handle, NULL)) {
2688+
grid_proxy_errmsg = "failed to initialize Globus data structures";
2689+
goto cleanup;
2690+
}
2691+
2692+
// We should have a proxy file, now, try to read it
2693+
if (globus_gsi_cred_read_proxy(src_handle, src_filename)) {
2694+
grid_proxy_errmsg = "unable to read proxy file";
2695+
goto cleanup;
2696+
}
2697+
2698+
if (globus_gsi_cred_get_lifetime(src_handle, &src_time_left)) {
2699+
grid_proxy_errmsg = "unable to extract expiration time";
2700+
goto cleanup;
2701+
}
2702+
if ( src_time_left < 0 ) {
2703+
src_time_left = 0;
2704+
}
2705+
2706+
if (globus_gsi_proxy_handle_init( &dst_proxy_handle, NULL )) {
2707+
grid_proxy_errmsg = "failed to initialize Globus data structures";
2708+
goto cleanup;
2709+
}
2710+
2711+
// lifetime == desired dst lifetime
2712+
// src_time_left == time left on src
2713+
if ( lifetime == 0 || lifetime > src_time_left ) {
2714+
lifetime = src_time_left;
2715+
}
2716+
if (globus_gsi_proxy_handle_set_time_valid( dst_proxy_handle, lifetime/60 )) {
2717+
grid_proxy_errmsg = "unable to set proxy expiration time";
2718+
goto cleanup;
2719+
}
2720+
2721+
if (globus_gsi_proxy_handle_set_type( dst_proxy_handle, cert_type)) {
2722+
grid_proxy_errmsg = "unable to set proxy type";
2723+
goto cleanup;
2724+
}
2725+
2726+
if (globus_gsi_proxy_create_signed( dst_proxy_handle, src_handle, &dst_handle)) {
2727+
grid_proxy_errmsg = "unable to generate proxy";
2728+
goto cleanup;
2729+
}
2730+
2731+
if (globus_gsi_cred_write_proxy( dst_handle, dst_filename )) {
2732+
grid_proxy_errmsg = "unable to write proxy file";
2733+
goto cleanup;
2734+
}
2735+
2736+
rc = 0;
2737+
2738+
cleanup:
2739+
if (src_handle) {
2740+
globus_gsi_cred_handle_destroy(src_handle);
2741+
}
2742+
if (dst_handle) {
2743+
globus_gsi_cred_handle_destroy(dst_handle);
2744+
}
2745+
if ( dst_handle ) {
2746+
globus_gsi_proxy_handle_destroy( dst_proxy_handle );
2747+
}
2748+
2749+
return rc;
2750+
}
25942751

25952752
static char *
25962753
limit_proxy(char* proxy_name, char *limited_proxy_name, char **error_message)
25972754
{
25982755
int seconds_left, hours_left, minutes_left;
25992756
char *limcommand;
26002757
int res;
2601-
char* globuslocation;
26022758
char *limit_command_output;
26032759
int tmpfd;
26042760
exec_cmd_t exe_command = EXEC_CMD_DEFAULT;
@@ -2639,31 +2795,15 @@ limit_proxy(char* proxy_name, char *limited_proxy_name, char **error_message)
26392795
if (error_message) *error_message = errmsg; else if (errmsg) free(errmsg);
26402796
return NULL;
26412797
}
2642-
2643-
globuslocation = (getenv("GLOBUS_LOCATION") ? getenv("GLOBUS_LOCATION") : "/opt/globus");
2644-
exe_command.command = make_message("%s/bin/grid-proxy-info -timeleft -file %s",
2645-
globuslocation, proxy_name);
2646-
if (exe_command.command == NULL)
2798+
else
26472799
{
2648-
fprintf(stderr, "blahpd: out of memory\n");
2649-
exit(1);
2800+
close(tmpfd);
26502801
}
2651-
res = execute_cmd(&exe_command);
2652-
free(exe_command.command);
26532802

2654-
if (res != 0)
2655-
{
2656-
perror("blahpd error invoking grid-proxy-info");
2657-
char * errmsg = make_message("blahpd error invoking grid-proxy-info; "
2658-
"exit code %d from grid-proxy-info");
2659-
if (limited_proxy_made_up_name != NULL) free(limited_proxy_made_up_name);
2660-
if (error_message && errmsg) *error_message = errmsg; else if (errmsg) free(errmsg);
2661-
return(NULL);
2662-
}
2663-
else
2664-
{
2665-
seconds_left = atoi(exe_command.output);
2666-
cleanup_cmd(&exe_command);
2803+
seconds_left = grid_proxy_info( proxy_name );
2804+
if ( seconds_left < 0 ) {
2805+
perror("blahpd error reading proxy lifetime");
2806+
return NULL;
26672807
}
26682808

26692809
limit_command_output = make_message("%s_XXXXXX", limited_proxy_name);
@@ -2686,18 +2826,9 @@ limit_proxy(char* proxy_name, char *limited_proxy_name, char **error_message)
26862826

26872827
get_lock_on_limited_proxy = config_test_boolean(config_get("blah_get_lock_on_limited_proxies",blah_config_handle));
26882828

2689-
if (seconds_left <= 0)
2690-
{
2829+
if (seconds_left <= 0) {
26912830
/* Something's wrong with the current proxy - use defaults */
2692-
exe_command.command = make_message("%s/bin/grid-proxy-init -limited -cert %s -key %s -out %s",
2693-
globuslocation, proxy_name, proxy_name, limit_command_output);
2694-
}
2695-
else
2696-
{
2697-
hours_left = (int)(seconds_left/3600);
2698-
minutes_left = (int)((seconds_left%3600)/60) + 1;
2699-
exe_command.command = make_message("%s/bin/grid-proxy-init -limited -valid %d:%d -cert %s -key %s -out %s",
2700-
globuslocation, hours_left, minutes_left, proxy_name, proxy_name, limit_command_output);
2831+
seconds_left = 12*60*60;
27012832
}
27022833

27032834
if ((limit_command_output == limited_proxy_name) &&
@@ -2728,8 +2859,7 @@ limit_proxy(char* proxy_name, char *limited_proxy_name, char **error_message)
27282859
}
27292860
}
27302861

2731-
res = execute_cmd(&exe_command);
2732-
free(exe_command.command);
2862+
res = grid_proxy_init( proxy_name, limit_command_output, seconds_left );
27332863

27342864
if ((limit_command_output == limited_proxy_name) &&
27352865
get_lock_on_limited_proxy)
@@ -2746,29 +2876,6 @@ limit_proxy(char* proxy_name, char *limited_proxy_name, char **error_message)
27462876
return(NULL);
27472877
}
27482878

2749-
/* If exitcode != 0 there may be a problem due to a warning by grid-proxy-init but */
2750-
/* the call may have been successful. We just check the temporary proxy */
2751-
if (exe_command.exit_code != 0)
2752-
{
2753-
int orig_exit_code = exe_command.exit_code;
2754-
cleanup_cmd(&exe_command);
2755-
exe_command.command = make_message("%s/bin/grid-proxy-info -f %s", globuslocation, limit_command_output);
2756-
res = execute_cmd(&exe_command);
2757-
free(exe_command.command);
2758-
if (res != 0 || exe_command.exit_code != 0)
2759-
{
2760-
char * errmsg = make_message("Failed to create limited proxy %s (grid-proxy-init "
2761-
"exit_code = %d; grid-proxy-info exit code %d)", limit_command_output, orig_exit_code, res != 0 ? res : exe_command.exit_code);
2762-
if (limit_command_output != limited_proxy_name)
2763-
free(limit_command_output);
2764-
if (limited_proxy_made_up_name != NULL) free(limited_proxy_made_up_name);
2765-
if (error_message && errmsg) *error_message= errmsg; else if(errmsg) free(errmsg);
2766-
return(NULL);
2767-
}
2768-
}
2769-
2770-
cleanup_cmd(&exe_command);
2771-
27722879
if (limit_command_output != limited_proxy_name)
27732880
{
27742881
if (get_lock_on_limited_proxy)

0 commit comments

Comments
 (0)