Skip to content
Snippets Groups Projects
Commit 13051398 authored by Mark Grondona's avatar Mark Grondona
Browse files

o update slurm_auth_init() to be MT-safe

parent dc31586e
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 The Regents of the University of California. * Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Kevin Tew <tew1@llnl.gov> et. al. * Written by Jay Windley <jwindley@lnxi.com>
* UCRL-CODE-2002-040. * UCRL-CODE-2002-040.
* *
* This file is part of SLURM, a resource management program. * This file is part of SLURM, a resource management program.
...@@ -47,12 +47,12 @@ ...@@ -47,12 +47,12 @@
typedef struct slurm_auth_ops { typedef struct slurm_auth_ops {
void * (*alloc) ( void ); void * (*alloc) ( void );
void (*free) ( void *cred ); void (*free) ( void *cred );
int (*activate) ( void *cred, int secs ); int (*activate) ( void *cred, int secs );
int (*verify) ( void *cred ); int (*verify) ( void *cred );
uid_t (*get_uid) ( void *cred ); uid_t (*get_uid) ( void *cred );
gid_t (*get_gid) ( void *cred ); gid_t (*get_gid) ( void *cred );
void (*pack) ( void *cred, Buf buf ); void (*pack) ( void *cred, Buf buf );
int (*unpack) ( void *cred, Buf buf ); int (*unpack) ( void *cred, Buf buf );
void (*print) ( void *cred, FILE *fp ); void (*print) ( void *cred, FILE *fp );
} slurm_auth_ops_t; } slurm_auth_ops_t;
...@@ -63,7 +63,7 @@ typedef struct slurm_auth_ops { ...@@ -63,7 +63,7 @@ typedef struct slurm_auth_ops {
* operations implemented pertinent to that context. * operations implemented pertinent to that context.
* *
* auth_type - the string (presumably from configuration files) * auth_type - the string (presumably from configuration files)
* describing the desired form of authentication, such as "auth/munged" * describing the desired form of authentication, such as "auth/munge"
* or "auth/kerberos" or "auth/none". * or "auth/kerberos" or "auth/none".
* *
* plugin_list - the plugin rack managing the loading and unloading of * plugin_list - the plugin rack managing the loading and unloading of
...@@ -86,11 +86,13 @@ struct slurm_auth_context { ...@@ -86,11 +86,13 @@ struct slurm_auth_context {
* A global authentication context. "Global" in the sense that there's * A global authentication context. "Global" in the sense that there's
* only one, with static bindings. We don't export it. * only one, with static bindings. We don't export it.
*/ */
static slurm_auth_context_t g_context = NULL; static slurm_auth_context_t g_context = NULL;
static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
static slurm_ctl_conf_t conf; static slurm_ctl_conf_t conf;
static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER;
static char * static char *
get_plugin_dir( void ) get_plugin_dir( void )
{ {
...@@ -228,23 +230,30 @@ slurm_auth_context_destroy( slurm_auth_context_t c ) ...@@ -228,23 +230,30 @@ slurm_auth_context_destroy( slurm_auth_context_t c )
int int
slurm_auth_init( void ) slurm_auth_init( void )
{ {
if ( g_context ) { int retval = SLURM_SUCCESS;
return SLURM_SUCCESS;
} slurm_mutex_lock( &context_lock );
if ( g_context )
goto done;
g_context = slurm_auth_context_create( get_auth_type() ); g_context = slurm_auth_context_create( get_auth_type() );
if ( g_context == NULL ) { if ( g_context == NULL ) {
verbose( "cannot create a context for %s", get_auth_type() ); verbose( "cannot create a context for %s", get_auth_type() );
return SLURM_ERROR; retval = SLURM_ERROR;
goto done;
} }
if ( slurm_auth_get_ops( g_context ) == NULL ) { if ( slurm_auth_get_ops( g_context ) == NULL ) {
verbose( "cannot resolve plugin operations" ); verbose( "cannot resolve plugin operations" );
return SLURM_ERROR; retval = SLURM_ERROR;
} else { } else {
return SLURM_SUCCESS; retval = SLURM_SUCCESS;
} }
done:
slurm_mutex_unlock( &context_lock );
return retval;
} }
/* /*
...@@ -361,12 +370,8 @@ c_slurm_auth_print( slurm_auth_context_t c, void *cred, FILE *fp ) ...@@ -361,12 +370,8 @@ c_slurm_auth_print( slurm_auth_context_t c, void *cred, FILE *fp )
void * void *
g_slurm_auth_alloc( void ) g_slurm_auth_alloc( void )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return NULL;
error( "can't allocate credential - authentication init failed" );
return NULL;
}
}
return (*(g_context->ops.alloc))(); return (*(g_context->ops.alloc))();
} }
...@@ -374,12 +379,8 @@ g_slurm_auth_alloc( void ) ...@@ -374,12 +379,8 @@ g_slurm_auth_alloc( void )
void void
g_slurm_auth_free( void *cred ) g_slurm_auth_free( void *cred )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return;
error( "can't free credential - authentication init failed" );
return;
}
}
(*(g_context->ops.free))( cred ); (*(g_context->ops.free))( cred );
} }
...@@ -387,12 +388,8 @@ g_slurm_auth_free( void *cred ) ...@@ -387,12 +388,8 @@ g_slurm_auth_free( void *cred )
int int
g_slurm_auth_activate( void *cred, int secs ) g_slurm_auth_activate( void *cred, int secs )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return SLURM_ERROR;
error( "can't activate credential - authentication init failed" );
return SLURM_ERROR;
}
}
return (*(g_context->ops.activate))( cred, secs ); return (*(g_context->ops.activate))( cred, secs );
} }
...@@ -400,12 +397,8 @@ g_slurm_auth_activate( void *cred, int secs ) ...@@ -400,12 +397,8 @@ g_slurm_auth_activate( void *cred, int secs )
int int
g_slurm_auth_verify( void *cred ) g_slurm_auth_verify( void *cred )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return SLURM_ERROR;
error( "can't verify credential - authentication init failed" );
return SLURM_ERROR;
}
}
return (*(g_context->ops.verify))( cred ); return (*(g_context->ops.verify))( cred );
} }
...@@ -413,12 +406,8 @@ g_slurm_auth_verify( void *cred ) ...@@ -413,12 +406,8 @@ g_slurm_auth_verify( void *cred )
uid_t uid_t
g_slurm_auth_get_uid( void *cred ) g_slurm_auth_get_uid( void *cred )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return SLURM_AUTH_NOBODY;
error( "can't get UID - authentication init failed" );
return SLURM_AUTH_NOBODY;
}
}
return (*(g_context->ops.get_uid))( cred ); return (*(g_context->ops.get_uid))( cred );
} }
...@@ -426,12 +415,8 @@ g_slurm_auth_get_uid( void *cred ) ...@@ -426,12 +415,8 @@ g_slurm_auth_get_uid( void *cred )
gid_t gid_t
g_slurm_auth_get_gid( void *cred ) g_slurm_auth_get_gid( void *cred )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return SLURM_AUTH_NOBODY;
error( "can't get GID - authentication init failed" );
return SLURM_AUTH_NOBODY;
}
}
return (*(g_context->ops.get_gid))( cred ); return (*(g_context->ops.get_gid))( cred );
} }
...@@ -439,12 +424,8 @@ g_slurm_auth_get_gid( void *cred ) ...@@ -439,12 +424,8 @@ g_slurm_auth_get_gid( void *cred )
void void
g_slurm_auth_pack( void *cred, Buf buf ) g_slurm_auth_pack( void *cred, Buf buf )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return;
error( "can't pack credential - authentication init failed" );
return;
}
}
(*(g_context->ops.pack))( cred, buf ); (*(g_context->ops.pack))( cred, buf );
} }
...@@ -452,12 +433,8 @@ g_slurm_auth_pack( void *cred, Buf buf ) ...@@ -452,12 +433,8 @@ g_slurm_auth_pack( void *cred, Buf buf )
int int
g_slurm_auth_unpack( void *cred, Buf buf ) g_slurm_auth_unpack( void *cred, Buf buf )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return SLURM_ERROR;
error( "can't unpack credential - authentication init failed" );
return SLURM_ERROR;
}
}
return (*(g_context->ops.unpack))( cred, buf ); return (*(g_context->ops.unpack))( cred, buf );
} }
...@@ -465,12 +442,8 @@ g_slurm_auth_unpack( void *cred, Buf buf ) ...@@ -465,12 +442,8 @@ g_slurm_auth_unpack( void *cred, Buf buf )
void void
g_slurm_auth_print( void *cred, FILE *fp ) g_slurm_auth_print( void *cred, FILE *fp )
{ {
if ( ! g_context ) { if ( slurm_auth_init() < 0 )
if ( slurm_auth_init() != SLURM_SUCCESS ) { return;
error( "can't print credential - authentication init failed" );
return;
}
}
(*(g_context->ops.print))( cred, fp ); (*(g_context->ops.print))( cred, fp );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment