RFC: Introduce pam_alloc.c for unnamed data#767
RFC: Introduce pam_alloc.c for unnamed data#767stoeckmann wants to merge 2 commits intolinux-pam:masterfrom
Conversation
The functions pam_add_alloc and pam_free_alloc manage unnamed data which has to be freed when pam_end is called. Use pam_alloc for data which is never looked up again but has to remain in heap for later uses. This can be a good foundation for data management of reentrant function implementations. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
| free(buffer); | ||
| return NULL; | ||
| D(("success")); | ||
| return result; |
There was a problem hiding this comment.
I don't remember where does the pamh == NULL case come from and whether it's used anywhere, but if it's used, then there is no way for buffer to be freed in that case.
There was a problem hiding this comment.
Indeed... Thanks for pointing out.
There was a problem hiding this comment.
The pamh == NULL case would also have to check if reentrant functions exist or not to be sure if the returned memory has to be freed.
Regardless, I've removed the memory split. Let's not make it more complicated.
The allocated memory can be stored without a name, simplifying the code. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
| extern int | ||
| _pam_add_alloc(pam_handle_t *pamh, void *data); | ||
|
|
||
| extern void | ||
| pam_modutil_cleanup(pam_handle_t *pamh, void *data, |
There was a problem hiding this comment.
The naming convention for this new interface is slightly confusing.
While all other pam_modutil functions have pam_modutil_ prefix, this one has _pam_ prefix instead.
Also, _pam_add_alloc was declared in two different header files, we don't normally do that.
There was a problem hiding this comment.
I want to use it not just for modules or modutil releated functionality, but outside of it as well, e.g. for _pam_mkargv. If there is a better way to define it so it's visible from modutil* and libpam itself, without exposing it to everyone else, please let me know.
Currently, the modutil functions like
pam_modutil_getpwnamadd data throughpam_set_dataif they have to manually handle allocations to support reentrant functions. This has one drawback:pam_set_dataa name has to be created. Later lookups of other names will iterate over these entries, which will slow down the search algorithm through the linked list.By adding
_pam_add_allocas well as_pam_free_allocit is possible to add "unnamed data" to the pam handle. Such data cannot be looked up again and will befreed whenpam_endis called.Such mechanism can be used outside of
pam_modutil_getpwnamas well, for example in_pam_mkargvto separate the char pointers from the chars. Which in turn allows us to remove the laststrcpycall from libpam.