lib/kadm5: improve kadm_c_ error handling
Perform error checking for each function call and consistently return errors at the point of failure. Refactor functions to use a common exit path. Preserve error messages stored in the kadm5_client_context.context when appropriate. Change-Id: I7aa04020e4de3454066f0d88ba805fed999dbd1a
This commit is contained in:

committed by
Nico Williams

parent
622c4ded2f
commit
50ebc1491a
@@ -48,34 +48,46 @@ kadm5_c_modify_principal(void *server_handle,
|
||||
krb5_data reply;
|
||||
|
||||
ret = _kadm5_connect(server_handle);
|
||||
if(ret)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
krb5_data_zero(&reply);
|
||||
|
||||
sp = krb5_storage_from_mem(buf, sizeof(buf));
|
||||
if (sp == NULL) {
|
||||
krb5_clear_error_message(context->context);
|
||||
return ENOMEM;
|
||||
ret = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
krb5_store_int32(sp, kadm_modify);
|
||||
kadm5_store_principal_ent(sp, princ);
|
||||
krb5_store_int32(sp, mask);
|
||||
ret = krb5_store_int32(sp, kadm_modify);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = kadm5_store_principal_ent(sp, princ);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = krb5_store_int32(sp, mask);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = _kadm5_client_send(context, sp);
|
||||
krb5_storage_free(sp);
|
||||
if(ret)
|
||||
return ret;
|
||||
if (ret)
|
||||
goto out_keep_error;
|
||||
ret = _kadm5_client_recv(context, &reply);
|
||||
if(ret)
|
||||
return ret;
|
||||
sp = krb5_storage_from_data (&reply);
|
||||
if (sp == NULL) {
|
||||
krb5_clear_error_message(context->context);
|
||||
krb5_data_free (&reply);
|
||||
return ENOMEM;
|
||||
}
|
||||
krb5_ret_int32(sp, &tmp);
|
||||
krb5_clear_error_message(context->context);
|
||||
if (ret)
|
||||
goto out_keep_error;
|
||||
krb5_storage_free(sp);
|
||||
krb5_data_free (&reply);
|
||||
return tmp;
|
||||
}
|
||||
sp = krb5_storage_from_data(&reply);
|
||||
if (sp == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
ret = krb5_ret_int32(sp, &tmp);
|
||||
if (ret == 0)
|
||||
ret = tmp;
|
||||
|
||||
out:
|
||||
krb5_clear_error_message(context->context);
|
||||
|
||||
out_keep_error:
|
||||
krb5_storage_free(sp);
|
||||
krb5_data_free(&reply);
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user