]> granicus.if.org Git - sudo/commitdiff
Add and document the %p escape in the password prompt.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 5 Jan 2008 23:59:28 +0000 (23:59 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 5 Jan 2008 23:59:28 +0000 (23:59 +0000)
Based on a patch from Patrick Schoenfeld.

check.c
sudo.pod
sudoers.pod

diff --git a/check.c b/check.c
index d4f0860930b0cc2ff293ceed1d0288eb1b3d84f1..5b0d6dcd640fe38b94be89eac019de5c95cedd3c 100644 (file)
--- 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);
index f4284212991141dbee6700fb7a982e1722512335..1ed93d46be7a7dbac126a9f0950ea5caf9411548 100644 (file)
--- a/sudo.pod
+++ b/sudo.pod
@@ -268,6 +268,11 @@ I<sudoers> 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<rootpw>, I<targetpw> and I<runaspw> flags in I<sudoers>)
+
 =item C<%U>
 
 expanded to the login name of the user the command will
index 09f51c6ba56a5271fca2a90136604dff1299331f..dd5babc1c197ce64899b8de11e7b262d047a3dd7 100644 (file)
@@ -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<rootpw>, I<targetpw> and I<runaspw> flags in I<sudoers>)
+
 =item C<%U>
 
 expanded to the login name of the user the command will