From 0fc0e3c86db1060d76eba65c7477baa8f2794130 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 5 Jan 2008 23:59:28 +0000 Subject: [PATCH] Add and document the %p escape in the password prompt. Based on a patch from Patrick Schoenfeld. --- check.c | 22 ++++++++++++++++++++++ sudo.pod | 5 +++++ sudoers.pod | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/check.c b/check.c index d4f086093..5b0d6dcd6 100644 --- a/check.c +++ b/check.c @@ -201,6 +201,16 @@ expand_prompt(old_prompt, user, host) len += strlen(user_host) - 2; subst = 1; break; + case 'p': + p++; + if (def_rootpw) + len += 2; + else if (def_targetpw || def_runaspw) + len += strlen(*user_runas) - 2; + else + len += strlen(user_name) - 2; + subst = 1; + break; case 'u': p++; len += strlen(user_name) - 2; @@ -242,6 +252,18 @@ expand_prompt(old_prompt, user, host) goto oflow; np += n; continue; + case 'p': + p++; + if (def_rootpw) + n = strlcpy(np, "root", np - endp); + else if (def_targetpw || def_runaspw) + n = strlcpy(np, *user_runas, np - endp); + else + n = strlcpy(np, user_name, np - endp); + if (n >= np - endp) + goto oflow; + np += n; + continue; case 'u': p++; n = strlcpy(np, user_name, np - endp); diff --git a/sudo.pod b/sudo.pod index f42842129..1ed93d46b 100644 --- a/sudo.pod +++ b/sudo.pod @@ -268,6 +268,11 @@ I option is set) expanded to the local hostname without the domain name +=item C<%p> + +expanded to the user whose password is being asked for (respects the +I, I and I flags in I) + =item C<%U> expanded to the login name of the user the command will diff --git a/sudoers.pod b/sudoers.pod index 09f51c6ba..dd5babc1c 100644 --- a/sudoers.pod +++ b/sudoers.pod @@ -847,6 +847,11 @@ option is set) expanded to the local hostname without the domain name +=item C<%p> + +expanded to the user whose password is being asked for (respects the +I, I and I flags in I) + =item C<%U> expanded to the login name of the user the command will -- 2.40.0