From 59b292aeb314ed4f7c14fa2508a421829da81f93 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 8 Apr 2008 08:56:32 +0000 Subject: Relevant BUGIDs: Purpose of commit: bugfix Commit summary: --------------- 2008-04-08 Tomas Mraz * libpam/pam_item.c (TRY_SET): Do not set when destination is identical to source. (pam_set_item): Do not overwrite destination when it is identical to source. --- libpam/pam_item.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'libpam/pam_item.c') diff --git a/libpam/pam_item.c b/libpam/pam_item.c index 724ea694..f3d794eb 100644 --- a/libpam/pam_item.c +++ b/libpam/pam_item.c @@ -11,13 +11,15 @@ #include #include -#define TRY_SET(X, Y) \ -{ \ - char *_TMP_ = _pam_strdup(Y); \ - if (_TMP_ == NULL && (Y) != NULL) \ - return PAM_BUF_ERR; \ - free(X); \ - (X) = _TMP_; \ +#define TRY_SET(X, Y) \ +{ \ + if ((X) != (Y)) { \ + char *_TMP_ = _pam_strdup(Y); \ + if (_TMP_ == NULL && (Y) != NULL) \ + return PAM_BUF_ERR; \ + free(X); \ + (X) = _TMP_; \ + } \ } /* functions */ @@ -76,8 +78,10 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) * modules. */ if (__PAM_FROM_MODULE(pamh)) { - _pam_overwrite(pamh->authtok); - TRY_SET(pamh->authtok, item); + if (pamh->authtok != item) { + _pam_overwrite(pamh->authtok); + TRY_SET(pamh->authtok, item); + } } else { retval = PAM_BAD_ITEM; } @@ -90,8 +94,10 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) * modules. */ if (__PAM_FROM_MODULE(pamh)) { - _pam_overwrite(pamh->oldauthtok); - TRY_SET(pamh->oldauthtok, item); + if (pamh->oldauthtok != item) { + _pam_overwrite(pamh->oldauthtok); + TRY_SET(pamh->oldauthtok, item); + } } else { retval = PAM_BAD_ITEM; } @@ -130,6 +136,8 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) break; case PAM_XAUTHDATA: + if (&pamh->xauth == item) + break; if (pamh->xauth.namelen) { _pam_overwrite(pamh->xauth.name); free(pamh->xauth.name); -- cgit v1.2.3 From a1131337d71a61da5b3b5e129545d3257a709480 Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Thu, 11 Dec 2008 19:41:49 +0000 Subject: Relevant BUGIDs: Purpose of commit: new feature Commit summary: --------------- 2008-12-10 Thorsten Kukuk * doc/man/pam_item_types_ext.inc.xml: Document PAM_AUTHTOK_TYPE. * libpam/pam_end.c (pam_end): Free authtok_type. * tests/tst-pam_get_item.c: Add PAM_AUTHTOK_TYPE as test case. * tests/tst-pam_set_item.c: Likewise. * libpam/pam_start.c (pam_start): Initialize xdisplay, xauth and authtok_type. * libpam/pam_get_authtok.c (pam_get_authtok): Rename "type" to "authtok_type". * modules/pam_cracklib/pam_cracklib.8.xml: Replace "type=" with "authtok_type=". * doc/man/pam_get_authtok.3.xml: Document authtok_type argument. * modules/pam_cracklib/pam_cracklib.c (pam_sm_chauthtok): Set type= argument as PAM_AUTHTOK_TYPE item. * libpam/pam_get_authtok.c (pam_get_authtok): If no type argument given, use PAM_AUTHTOK_TYPE item. * libpam/pam_item.c (pam_get_item): Fetch PAM_AUTHTOK_TYPE item. (pam_set_item): Store PAM_AUTHTOK_TYPE item. * libpam/pam_private.h: Add authtok_type to pam_handle. * libpam/include/security/_pam_types.h (PAM_AUTHTOK_TYPE): New. --- libpam/pam_item.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libpam/pam_item.c') diff --git a/libpam/pam_item.c b/libpam/pam_item.c index f3d794eb..ed478a4a 100644 --- a/libpam/pam_item.c +++ b/libpam/pam_item.c @@ -151,7 +151,7 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) if ((pamh->xauth.name=_pam_strdup(pamh->xauth.name)) == NULL) { memset(&pamh->xauth, '\0', sizeof(pamh->xauth)); return PAM_BUF_ERR; - } + } if ((pamh->xauth.data=_pam_memdup(pamh->xauth.data, pamh->xauth.datalen)) == NULL) { _pam_overwrite(pamh->xauth.name); @@ -161,6 +161,10 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) } break; + case PAM_AUTHTOK_TYPE: + TRY_SET(pamh->authtok_type, item); + break; + default: retval = PAM_BAD_ITEM; } @@ -251,6 +255,10 @@ int pam_get_item (const pam_handle_t *pamh, int item_type, const void **item) *item = &pamh->xauth; break; + case PAM_AUTHTOK_TYPE: + *item = pamh->authtok_type; + break; + default: retval = PAM_BAD_ITEM; } -- cgit v1.2.3