From df673b9b2e174240f4a94388c4d58e5a6334d601 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Mon, 17 Oct 2016 14:18:24 +0200 Subject: pam_ftp: Properly use the first name from the supplied list * modules/pam_ftp/pam_ftp.c (lookup): Return first user from the list of anonymous users if user name matches. (pam_sm_authenticate): Free the returned value allocated in lookup(). --- modules/pam_ftp/pam_ftp.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'modules/pam_ftp') diff --git a/modules/pam_ftp/pam_ftp.c b/modules/pam_ftp/pam_ftp.c index 6b6cf2a0..1c2f1456 100644 --- a/modules/pam_ftp/pam_ftp.c +++ b/modules/pam_ftp/pam_ftp.c @@ -71,11 +71,10 @@ _pam_parse(pam_handle_t *pamh, int argc, const char **argv, const char **users) * return 1 if listed 0 if not. */ -static int lookup(const char *name, const char *list, const char **_user) +static int lookup(const char *name, const char *list, char **_user) { int anon = 0; - *_user = name; /* this is the default */ if (list && *list) { const char *l; char *list_copy, *x; @@ -86,12 +85,14 @@ static int lookup(const char *name, const char *list, const char **_user) while (list_copy && (l = strtok_r(x, ",", &sptr))) { x = NULL; if (!strcmp(name, l)) { - *_user = list; + *_user = list_copy; anon = 1; + break; } } - _pam_overwrite(list_copy); - _pam_drop(list_copy); + if (*_user != list_copy) { + free(list_copy); + } } else { #define MAX_L 2 static const char *l[MAX_L] = { "ftp", "anonymous" }; @@ -99,7 +100,7 @@ static int lookup(const char *name, const char *list, const char **_user) for (i=0; i