git-svn-id: https://modwaklog.svn.sourceforge.net/svnroot/modwaklog/trunk/modwaklog@16
0d961d1b-a432-0410-8fea-
cc29f225fe07
-pioctl_cleanup( void *data )
+token_cleanup( void *data )
{
request_rec *r = (request_rec *)data;
{
request_rec *r = (request_rec *)data;
-waklog_ktinit( server_rec *s )
+waklog_kinit( server_rec *s )
{
krb5_error_code kerror;
{
krb5_error_code kerror;
- krb5_context kcontext;
- krb5_principal kprinc;
+ krb5_context kcontext = NULL;
+ krb5_principal kprinc = NULL;
krb5_get_init_creds_opt kopts;
krb5_creds v5creds;
CREDENTIALS v4creds;
krb5_get_init_creds_opt kopts;
krb5_creds v5creds;
CREDENTIALS v4creds;
- krb5_ccache kccache;
- krb5_keytab keytab = 0;
+ krb5_ccache kccache = NULL;
+ krb5_keytab keytab = NULL;
char ktbuf[ MAX_KEYTAB_NAME_LEN + 1 ];
char ktbuf[ MAX_KEYTAB_NAME_LEN + 1 ];
waklog_host_config *cfg;
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
waklog_host_config *cfg;
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
- "mod_waklog: waklog_ktinit called" );
+ "mod_waklog: waklog_kinit called" );
if (( kerror = krb5_init_context( &kcontext ))) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
if (( kerror = krb5_init_context( &kcontext ))) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
if (( kerror = krb5_parse_name( kcontext, PRINCIPAL, &kprinc ))) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
if (( kerror = krb5_parse_name( kcontext, PRINCIPAL, &kprinc ))) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
krb5_get_init_creds_opt_init( &kopts );
}
krb5_get_init_creds_opt_init( &kopts );
ap_log_error( APLOG_MARK, APLOG_ERR, s,
"server configuration error" );
ap_log_error( APLOG_MARK, APLOG_ERR, s,
"server configuration error" );
}
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
}
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
- "mod_waklog: waklog_ktinit using: %s", ktbuf );
+ "mod_waklog: waklog_kinit using: %s", ktbuf );
if (( kerror = krb5_kt_resolve( kcontext, ktbuf, &keytab )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
if (( kerror = krb5_kt_resolve( kcontext, ktbuf, &keytab )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
if (( kerror = krb5_verify_init_creds( kcontext, &v5creds,
}
if (( kerror = krb5_verify_init_creds( kcontext, &v5creds,
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
if (( kerror = krb5_cc_initialize( kcontext, kccache, kprinc )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
if (( kerror = krb5_cc_initialize( kcontext, kccache, kprinc )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
- if (( kerror = krb5_cc_store_cred( kcontext, kccache, &v5creds )) != 0 ) {
+ kerror = krb5_cc_store_cred( kcontext, kccache, &v5creds );
+ krb5_free_cred_contents( kcontext, &v5creds );
+ if ( kerror != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, s,
(char *)error_message( kerror ));
}
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
}
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
- "mod_waklog: waklog_ktinit success" );
-
-cleanup6: if ( v5creds.client == kprinc ) {
- v5creds.client = 0;
- }
- krb5_free_cred_contents( kcontext, &v5creds );
-cleanup5: (void)krb5_kt_close( kcontext, keytab );
-cleanup4: krb5_free_principal( kcontext, kprinc );
-cleanup3: krb5_cc_close( kcontext, kccache );
-cleanup2: krb5_free_context( kcontext );
-cleanup1:
+ "mod_waklog: waklog_kinit success" );
+
+cleanup:
+ if ( keytab )
+ (void)krb5_kt_close( kcontext, keytab );
+ if ( kprinc )
+ krb5_free_principal( kcontext, kprinc );
+ if ( kccache )
+ krb5_cc_close( kcontext, kccache );
+ if ( kcontext )
+ krb5_free_context( kcontext );
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
- "mod_waklog: waklog_ktinit: exiting" );
+ "mod_waklog: waklog_kinit: exiting" );
const char *k4path = NULL;
const char *k5path = NULL;
krb5_error_code kerror;
const char *k4path = NULL;
const char *k5path = NULL;
krb5_error_code kerror;
+ krb5_context kcontext = NULL;
krb5_creds increds;
krb5_creds *v5credsp = NULL;
CREDENTIALS v4creds;
krb5_creds increds;
krb5_creds *v5credsp = NULL;
CREDENTIALS v4creds;
+ krb5_ccache kccache = NULL;
struct ktc_principal server = { "afs", "", "umich.edu" };
struct ktc_principal client;
struct ktc_token token;
struct ktc_principal server = { "afs", "", "umich.edu" };
struct ktc_principal client;
struct ktc_token token;
if ( !k5path || !k4path ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: waklog_aklog giving up" );
if ( !k5path || !k4path ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: waklog_aklog giving up" );
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
}
memset( (char *)&increds, 0, sizeof(increds));
}
memset( (char *)&increds, 0, sizeof(increds));
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
}
if (( kerror = krb5_cc_resolve( kcontext, k5path, &kccache )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
}
if (( kerror = krb5_cc_resolve( kcontext, k5path, &kccache )) != 0 ) {
ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
(char *)error_message( kerror ));
&increds, &v5credsp ) ) ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: krb5_get_credentials: %s", krb_err_txt[ kerror ] );
&increds, &v5credsp ) ) ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: krb5_get_credentials: %s", krb_err_txt[ kerror ] );
}
/* get the V4 credentials */
if (( kerror = krb524_convert_creds_kdc( kcontext, v5credsp, &v4creds ) ) ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: krb524_convert_creds_kdc: %s", krb_err_txt[ kerror ] );
}
/* get the V4 credentials */
if (( kerror = krb524_convert_creds_kdc( kcontext, v5credsp, &v4creds ) ) ) {
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: krb524_convert_creds_kdc: %s", krb_err_txt[ kerror ] );
}
/* assemble the token */
}
/* assemble the token */
memmove( &child->token, &token, sizeof( struct ktc_token ) );
/* we'll need to unlog when this connection is done. */
memmove( &child->token, &token, sizeof( struct ktc_token ) );
/* we'll need to unlog when this connection is done. */
- ap_register_cleanup( r->pool, (void *)r, pioctl_cleanup, ap_null_cleanup );
+ ap_register_cleanup( r->pool, (void *)r, token_cleanup, ap_null_cleanup );
- krb5_free_cred_contents( kcontext, v5credsp );
- krb5_free_principal( kcontext, increds.client );
- krb5_cc_close( kcontext, kccache );
- krb5_free_context( kcontext );
+cleanup:
+ if ( v5credsp )
+ krb5_free_cred_contents( kcontext, v5credsp );
+ if ( increds.client )
+ krb5_free_principal( kcontext, increds.client );
+ if ( increds.server )
+ krb5_free_principal( kcontext, increds.server );
+ if ( kccache )
+ krb5_cc_close( kcontext, kccache );
+ if ( kcontext )
+ krb5_free_context( kcontext );
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: finished with waklog_aklog" );
ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
"mod_waklog: finished with waklog_aklog" );
sleep( 300 /* 10*60*60 - 5*60 */ );
}
sleep( 300 /* 10*60*60 - 5*60 */ );
}